Results 1 to 2 of 2

Thread: i want to access a file at http://localhost/project

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2002
    Location
    Pakistan
    Posts
    32

    i want to access a file at 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 the file you running is placed.

    So actually i want to go to the original 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
    Lively Member
    Join Date
    Dec 1999
    Posts
    106
    Not sure if I fully understand what you ware doing here but you might try this ....

    .
    .
    // get the path to the assembly that created this
    string myPath = this.GetType().Assembly.CodeBase;

    // clean up the path
    string assembyDir = GetPath(myPath);
    .
    .

    private string GetPath(string assembly)
    {
    string path = "";
    if(assembly.ToLower().StartsWith("file:///"))
    {
    path = assembly.Substring(8);
    }
    int idx = path.LastIndexOf("/");
    path = path.Substring(0,idx + 1);
    return path;
    }

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