Showing posts with label GetCurrentDirectory(). Show all posts
Showing posts with label GetCurrentDirectory(). Show all posts

Tuesday, 17 April 2012

When an ASP.NET page is executed, the thread used to execute the code that generates the page by default has a current working directory of that page. It uses this directory as its base directory . If you pass a relative filename into any System.IO class, the file is assumed to be located relative to the current working directory.

The default working directory for the ASP.NET Development Server is a directory under your Visual Studio install root. If you installed Visual Studio in C:\Program Files. Your ASP.NET Development Server working directory would be C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0.

To get the location of working directory using GetCurrentDirectory() method. This method is exist in System.IO.Directory class.
To set the location of working direcotry using SetCurrentDirectory() method. This method is exist in System.IO.Directory class.

Here are sample example :
    lblCurrentDirectory.Text = System.IO.Directory.GetCurrentDirectory();
    //Set New current directory
    System.IO.Directory.SetCurrentDirectory(MapPath(""));
    lblNewCurrentDirectory.Text = System.IO.Directory.GetCurrentDirectory();