File Path not relative to dll?

R

Rob Taylor

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
 
D

David R. Longnecker

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
 
R

Rob Taylor

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
 
P

Patrice

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).
 
R

Rob Taylor

Patrice,

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

Rob
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top