Surendra Sharma

Surendra Sharma

Search This Blog

Wednesday, June 12, 2013

Steps for accessing TFS

1.       Connect to VPN from Visual Studio from View -> Team Explorer.
2.       Try to access the code base using team foundation. Use the login credentials with domain name like “DomainNameXYZ\UserNameXYZ”. Please follow the following steps
a.       Go to team foundation server. Either through View -> Team explorer OR Tools -> connect to Team foundation server
b.      This will open one window where you can add server
c.       After you clicked on ‘Add Server’ it will open one window where you can add  URL “http://ServerLinkXYZ”

d.      Select any “ProjectXYZ” and map its “Trunk” folder with your local folder like “C:\ProjectXYZ\Code\Trunk”.

Calling base class constructor from derived class Constructor

If you want to call one constructor from another in a class itself, then use this()

If you want to call base class constructor from derived class constructor, then use base().

If you are not calling any base class constructor from derived class, then always base class default constructor will called.

Sample Program:

    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            DerivedClass objDerivedClass = new DerivedClass();
            //Output :  BaseClass - Default constructor
            //          DerivedClass - Default constructor

            DerivedClass objDerivedClass1 = new DerivedClass("PageId1234");
            //Output :  BaseClass - Default constructor
            //          DerivedClass - Default constructor
            //          DerivedClass - Overloaded constructor calling Default constructor using this()

            DerivedClass objDerivedClass2 = new DerivedClass(10800, "Student");
            //Output :  BaseClass - Overloaded constructor
            //          DerivedClass - Overloaded constructor calling base class constructor

            Console.ReadLine();

        }
    }

    public partial class BaseClass
    {
        int tempCommandTimeout = 0;

        /// <summary>
        /// Default constructor
        /// </summary>
        public BaseClass()
        {
           tempCommandTimeout = 300;
           Console.WriteLine("BaseClass - Default constructor");
        }

        /// <summary>
        /// Overloaded constructor to Set Command-timeout
        /// </summary>
        /// <param name="iCommandTimeout"></param>
        public BaseClass(int iCommandTimeout)
        {
            tempCommandTimeout = iCommandTimeout;
            Console.WriteLine("BaseClass - Overloaded constructor");
        }
    }

    public partial class DerivedClass : BaseClass
    {
        string TableName = "";
        string PageID = "";

        /// <summary>
        /// Default constructor
        /// </summary>
        public DerivedClass()
        {
            this.TableName = "Employee";
            Console.WriteLine("DerivedClass - Default constructor");
        }

        /// <summary>
        /// Overloaded constructor calling Default constructor using this()
        /// </summary>
        /// <param name="ePageID"></param>
        public DerivedClass(string ePageID)
            : this()
        {
            PageID = ePageID;
            Console.WriteLine("DerivedClass - Overloaded constructor calling Default constructor using this()");
        }

        /// <summary>
        /// Overloaded constructor calling base class constructor to Set Command-timeout
        /// </summary>
        /// <param name="iCommandTimeout"></param>
        public DerivedClass(int iCommandTimeout, string strTableName)
            : base(iCommandTimeout)
        {

            TableName = strTableName;
            Console.WriteLine("DerivedClass - Overloaded constructor calling base class constructor");
        }
    }

Set Command Timeout for SqlCommand

If you are running store procedure or SQL query from C# which is taking long time to run, set Command-timeout of SQL Command object in seconds.
For this, you don’t need to set connection timeout in connection string in config file.
A value 0 means no limit.
Suppose you want to set command time out for 3 hour = 3 * 60 * 60 = 10800 sec
SqlCommand objSqlCommand = new SqlCommand();

objSqlCommand.CommandTimeout = 10800; 

File Pointer in StreamReader

If you are reading from file using StreamReader by using string fileContent = sr.ReadToEnd();
and now if you will try to read it again using while ((line = sr.ReadLine()) != null)  for the same object, then you will not get any single word as file pointer is on end of file due to sr.ReadToEnd();
StreamReader sr = new StreamReader(fullFilePath);

if (sr != null)
{
string fileContent = sr.ReadToEnd();

if (fileContent.Contains(",") || fileContent.Contains("-"))
{
     
StringBuilder sbZipRadius = new StringBuilder();
string line = string.Empty;

//Read file line by line
while ((line = sr.ReadLine()) != null)
{
//if ',' exists in the line,it will be replace by '-'
line = line.Replace(',', '-');
}
}

//Close the file
sr.Close();
sr.Dispose();

}

Wednesday, June 5, 2013

IIS 7.5 error: Handler “PageHandlerFactory-Integrated” has a bad module “ManagedPipelineHandler” in its module list

Run Cmd “%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i

Bind Client Script function

public static void BindClientScript(string script, Control control) {
            ScriptManager.RegisterStartupScript(control, typeof(Page), Guid.NewGuid().ToString(), script, true);


        }

How to Get Geocoding Search Results

public static XElement GetGeocodingSearchResults(string address) {
            // Use the Google Geocoding service to get information about the user-entered address
            // See http://code.google.com/apis/maps/documentation/geocoding/index.html for more info...
            var url = String.Format("http://maps.google.com/maps/api/geocode/xml?address={0}&sensor=false", HttpContext.Current.Server.UrlEncode(address));

            // Load the XML into an XElement object (whee, LINQ to XML!)
            var results = XElement.Load(url);

            // Check the status
            var status = results.Element("status").Value;
            if (status != "OK" && status != "ZERO_RESULTS")
                // Whoops, something else was wrong with the request...
                throw new ApplicationException("There was an error with Google's Geocoding Service: " + status);

            return results;

        }