Monday, 9 February 2015

How to change local folder for TFS

To change local folder path for TFS do the following steps:

1- Connect to your TFS
2- Go to File > Source Control > Workspaces
3- Click on Edit... the workspace which is causing the problem
4- Change the local folder and click on OK.

Sunday, 28 September 2014

CONVERT IP ADDRESS INTO URL IN C#

To convert an IP (Internet protocol) address into corresponding Url (Uniform Resource Locator)  in C#, ASP.NET you need a help of IPHostEntry and  IPAddress class. Make an object of this call and call the Dns.GetHostEntry() class to find the HostName against the Url.

IPAddress addr = IPAddress.Parse("195.175.254.2");
IPHostEntry entry = Dns.GetHostEntry(addr);
Response.Write(entry.HostName.ToString());

entry.HostName.ToString() will return the host name of the IP address.

Wednesday, 6 August 2014

Export the data in excel format

Below is the code.

private void Save(string detail)
    {
        Response.ContentType = "application/ms-excel";
        Response.AddHeader("content-disposition", "attachment; filename=Data.xls");
        Response.Write("<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">");
        Response.Write("<head>");
        Response.Write("<meta http-equiv=\"Content-Type\" content=\"text/html;charset=windows-1252\">");
        Response.Write("<!--[if gte mso 9]>");
        Response.Write("<xml>");
        Response.Write("<x:ExcelWorkbook>");
        Response.Write("<x:ExcelWorksheets>");
        Response.Write("<x:ExcelWorksheet>");      
        Response.Write("<x:Name>Personal Detail</x:Name>");
        Response.Write("<x:WorksheetOptions>");      
        Response.Write("<x:Panes>");
        Response.Write("</x:Panes>");
        Response.Write("</x:WorksheetOptions>");
        Response.Write("</x:ExcelWorksheet>");
        Response.Write("</x:ExcelWorksheets>");
        Response.Write("</x:ExcelWorkbook>");
        Response.Write("</xml>");
        Response.Write("<![endif]-->");
        Response.Write("</head>");
        Response.Write("<body>");
        Response.Write(detail);
        Response.Write("</body>");
        Response.Write("</html>");
        // --------------------------------  
        Response.End();
    }

Wednesday, 23 July 2014

Cross-thread operation not valid: Control 'textBox1' accessed from a thread other than the thread it was created on.

Set ConcurrencyMode to Reentrant as shown below above the class implemented the Service contract interface.
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]

Set the property of the Form/Page class in the client application as below.
[CallbackBehavior(UseSynchronizationContext = false)]

Set the text box property CheckForIllegalCrossThreadCalls to false like below in the method describing duplext contract.
TextBox.CheckForIllegalCrossThreadCalls = false;