Results 1 to 3 of 3

Thread: how to reach orignal directory http://localhost/project/....?

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2002
    Location
    Pakistan
    Posts
    32

    Question how to reach orignal directory http://localhost/project/....?

    I am working in asp.net and C#. I have made a class library (dll) in which i have placed my connection objects.

    There for some reason i need to reach the path of my server which is http://localhost/project/ . I want to access a file placed in this directory.

    I tried System.IO's Directory.GetCurrentDirectory but it takes me to C:\Winnt\System32. And in the explanation at msdn it says this function takes you to the current directory and not to the original directory where your file you running is placed.

    So actually i want to go to the actual directory.

    Any help in this regard will be highly appreciated.

    As for Server.MapPath() it doesn't run in the refrenced class library ... so i have to do it somehow with system.IO but not getting to it.

    Regards,

    Harris Moin
    You'll get life just for once so don't waste it .......

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Actually server.mappath is correct. But if you are trying tyo use it in a seperate class(ie not the code behind) you have to get the HttpContext first. Use this

    System.Web.HttpContext.Current.Server.MapPath
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Try this:

    Code:
        Response.Write(Server.MapPath(Request.ApplicationPath));

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width