Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

File Path not relative to dll?

0 views
Skip to first unread message

Rob Taylor

unread,
Oct 10, 2007, 5:00:04 PM10/10/07
to
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

unread,
Oct 10, 2007, 5:18:00 PM10/10/07
to
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

Rob Taylor

unread,
Oct 10, 2007, 7:35:51 PM10/10/07
to
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

Patrice

unread,
Oct 11, 2007, 4:34:07 AM10/11/07
to
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" <anon...@devdex.com> a écrit dans le message de news:
%23LgbMZ5...@TK2MSFTNGP05.phx.gbl...

Rob Taylor

unread,
Oct 11, 2007, 11:50:51 AM10/11/07
to
Patrice,

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

Rob

0 new messages