File Path not relative to dll?

Discussion in 'ASP .Net' started by Rob Taylor, Oct 10, 2007.

  1. Rob Taylor

    Rob Taylor Guest

    Everytime I run a particular project, my System.CurrentDirectory points
    to "C:\\Program Files\\Microsoft Visual Studio 8\\Common7\\IDE" but my
    Solution/Project is under c:\projects\.... As a result when my .dlls
    try to find an XML file to parse using xmlTextReader, they are unable to
    find the file based upon the path. I don't want to hard code the path
    as that is impractical.

    Everything I've seen in my research indicates that paths are relative to
    the dll/exe making the call, but not in this case. Is this some project
    setting I need to set or what did I miss?

    Thank you.

    Rob

    *** Sent via Developersdex http://www.developersdex.com ***
     
    Rob Taylor, Oct 10, 2007
    #1
    1. Advertising

  2. I'm sure someone can chime in with an official article, but it's been my
    experience that code-behind and aspx pages do follow the current directory
    because of context; however, compiled libraries default to either the \web
    server extensions\bin directory of the VSIDE directory (if using the packaged
    web server in VS).

    You can get around that though with Server.MapPath("~/YourFileHere.xml")
    or pass the full path into your method as a parameter from your client web
    pages.

    HTH.

    -dl

    --
    David R. Longnecker
    http://blog.tiredstudent.com

    > Everytime I run a particular project, my System.CurrentDirectory
    > points to "C:\\Program Files\\Microsoft Visual Studio 8\\Common7\\IDE"
    > but my Solution/Project is under c:\projects\.... As a result when my
    > .dlls try to find an XML file to parse using xmlTextReader, they are
    > unable to find the file based upon the path. I don't want to hard
    > code the path as that is impractical.
    >
    > Everything I've seen in my research indicates that paths are relative
    > to the dll/exe making the call, but not in this case. Is this some
    > project setting I need to set or what did I miss?
    >
    > Thank you.
    >
    > Rob
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    >
     
    David R. Longnecker, Oct 10, 2007
    #2
    1. Advertising

  3. Rob Taylor

    Rob Taylor Guest

    David,

    Thank you! I looked at Server.MapPath, but it doesn't seem to be an
    object supported in my C# project (I'm guessing it's because the project
    is not in the Website itself). Did I miss something here?

    If I have to, I'll pass a variable to the dll, but I'd rather get the
    path from the dll if possible.

    Thank you for your help. I appreciated it.

    Robert

    *** Sent via Developersdex http://www.developersdex.com ***
     
    Rob Taylor, Oct 11, 2007
    #3
  4. Rob Taylor

    Patrice Guest

    Keep in mind that the "current directory" doesn't mean much in an ASP.NET
    application (this is likely c:\windows\system32 as your code runs anyway as
    part of IIS).

    You could get the config from the hosting environment (from the AppDomain or
    by using System.Web.HttpContext.Current etc...) but my personal preference
    would be likely to always resolve the full path and provide this to file
    related functions called from an ASP.NET application (it doesn't prevent to
    use relative path when used outside a web application where it's makes more
    sense).


    --
    Patrice


    "Rob Taylor" <> a écrit dans le message de news:
    %...
    > David,
    >
    > Thank you! I looked at Server.MapPath, but it doesn't seem to be an
    > object supported in my C# project (I'm guessing it's because the project
    > is not in the Website itself). Did I miss something here?
    >
    > If I have to, I'll pass a variable to the dll, but I'd rather get the
    > path from the dll if possible.
    >
    > Thank you for your help. I appreciated it.
    >
    > Robert
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
     
    Patrice, Oct 11, 2007
    #4
  5. Rob Taylor

    Rob Taylor Guest

    Patrice,

    Thanks. I'll take a look at the objects and methods. I appreciate the
    help.

    Rob

    *** Sent via Developersdex http://www.developersdex.com ***
     
    Rob Taylor, Oct 11, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Anushi
    Replies:
    5
    Views:
    8,781
  2. Matt
    Replies:
    3
    Views:
    19,567
    Sudsy
    Jul 8, 2004
  3. Thomas Guettler
    Replies:
    3
    Views:
    761
    Andrei
    Oct 27, 2003
  4. Oren
    Replies:
    1
    Views:
    551
    Michael D. Ober
    Apr 29, 2007
  5. Nigel Wilkinson
    Replies:
    2
    Views:
    389
    Nigel Wilkinson
    Jul 25, 2005
Loading...

Share This Page