Tuesday, 17 April 2012

Beginning .Net : Set and Get current directory in .Net

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();

23 comments:

  1. The default working directory for the ASP.NET Development Server is a directory under your Visual Studio.
    Thanks for sharing this..

    ReplyDelete
    Replies
    1. Hello Keith,
      Thanks for your valuable comment.

      Delete
  2. In asp.net get and post method is very important..with help of these we are retrieve the method or value..

    ReplyDelete
    Replies
    1. Hello Lani,
      Thanks for your valuable comment.

      Delete
  3. To set the location of working direcotry using SetCurrentDirectory() method. This method is exist in System.IO.Directory class.thanks for sharing this.

    ReplyDelete
    Replies
    1. Hello Ulsses,
      Thanks for your valuable comment.

      Delete
  4. I am very pleased to find this blog. I want to thank for your time for this wonderful read!!! Keep Sharing, I'll surely be looking for more.

    ReplyDelete
    Replies
    1. Hello Declan,
      Thanks for your valuable comment.

      Delete
  5. Excellent blog to all of us,this blog really good information for the future. Thanks

    ReplyDelete
    Replies
    1. Hello Auila,
      Thanks for your valuable comment.

      Delete
  6. WoW! Like your site very much, i will come here again and again.

    ReplyDelete
    Replies
    1. Hello Camille,
      Thanks for your valuable comment.

      Delete
  7. Nice site, I just dugg this keep up the good work!. . . . . .

    ReplyDelete
    Replies
    1. Hello Alfreda,
      Thanks for your valuable comment.

      Delete
  8. This really is truly excellent details, appreciate it.

    ReplyDelete
  9. Thanks for a awesome post and interesting comments. I found this post while surfing for some popular lyrics. Thanks for sharing this post.

    ReplyDelete
  10. I can see that you are an expert at your field! I am launching a website soon, and your details will be very useful for me.. Thanks for all your help and expecting you all the success.

    ReplyDelete
  11. This is just excellent, I really really like it. We need several weblogs like this. You have excellent details and it is really excellent. I saved this web page and will come returning.

    ReplyDelete
  12. 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.

    ReplyDelete
  13. 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.

    ReplyDelete
  14. As a developer, you have to be able to point out best commercial experience of developing linked database architectures along with designers that ought to be accountable for building design and style of product features, code, tests and ensure of restricted deadlines are fulfilled.

    ReplyDelete
  15. In an ASP.NET application, this will be the application root directory, not the bin subfolder which is probably what you usually want.

    ReplyDelete
  16. This is really a nice blog with great post, I would really like to keep reading here. Thanks for this nice article, valuable information for all and of course I will recommend my friends to read this for sure.

    ReplyDelete