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

40 comments:

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

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

    ReplyDelete
  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
  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
  17. Hello! This is my first visit to your blog! We are a team of volunteers and starting a new initiative in a community in the same niche. Your blog provided us useful information to work on. You have done an outstanding job.

    AWS Online Training | Online AWS Certification Course - Gangboard

    AWS Training in Chennai | AWS Training Institute in Chennai Velachery, Tambaram, OMR
    AWS Training in Bangalore |Best AWS Training Institute in BTM ,Marathahalli

    ReplyDelete
  18. Thanks you for sharing this unique useful information content with us. Really awesome work. keep on blogging
    Online DevOps Certification Course - Gangboard
    Best Devops Training institute in Chennai

    ReplyDelete
  19. Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.

    rpa training in velachery| rpa training in tambaram |rpa training in sholinganallur | rpa training in annanagar| rpa training in kalyannagar

    ReplyDelete
  20. Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.

    Java interview questions and answers | Core Java interview questions and answers

    ReplyDelete
  21. Have you been thinking about the power sources and the tiles whom use blocks I wanted to thank you for this great read!! I definitely enjoyed every little bit of it and I have you bookmarked to check out the new stuff you post

    devops online training

    aws online training

    data science with python online training

    data science online training

    rpa online training

    ReplyDelete
  22. I would assume that we use more than the eyes to gauge a person's feelings. Mouth. Body language. Even voice. You could at least have given us a face in this test.
    Microsoft Azure online training
    Selenium online training
    Java online training
    Python online training
    uipath online training

    ReplyDelete