473,394 Members | 1,951 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

File Path not relative to dll?

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 ***
Oct 10 '07 #1
4 1903
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 ***

Oct 10 '07 #2
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 ***
Oct 10 '07 #3
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" <an*******@devdex.coma écrit dans le message de news:
%2****************@TK2MSFTNGP05.phx.gbl...
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 ***

Oct 11 '07 #4
Patrice,

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

Rob

*** Sent via Developersdex http://www.developersdex.com ***
Oct 11 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Parzival | last post by:
I have a package that includes some data files. I am planning to use a distutils setup script to install the package. How can I compute a path name for such a data file that will always be relative...
3
by: StGo | last post by:
How can i read/write file's custom attributs(like subject,author...) in C#??? Thanks :))
1
by: Alex VanderWoude | last post by:
I am trying to <include> some text into an XML documentation topic, but that text is stored in a file that is in a different directory than the "current" XML file. Using a relative path does not...
1
by: Dave | last post by:
I've built a custom server control that reads an xml file and builds a left side navigation system. When I drop that server control into a user control that will hold the left side navigation for...
9
by: semesm22 | last post by:
hello all, i am using asp.net with IIS on a Windows XP machine to open an Access database, and i know that this topic has been posted on forums hundreds of times, but i can't find an answer that...
7
by: Ben R. | last post by:
Hi, I'm working on an ASP.NET 2.0 site and my hosting provider has the root in a different place than I have it locally which is not a problem for most things, except for the access oledb...
5
by: Al | last post by:
Hi all We have created a xml file that imports a single project using the Import element. This project compiles to a class library, but has references to two other projects that are also class...
10
by: Ben Finney | last post by:
Howdy all, Question: I have Python modules named without '.py' as the extension, and I'd like to be able to import them. How can I do that? Background: On Unix, I write programs intended to...
17
by: Paul | last post by:
On my development computer, I have virtual named host set up, like www.site1.lab. When I upload those to my web site for customer review under mywebsite.com/clients/site1/ it throws some of the...
5
by: Eugene Anthony | last post by:
ds1.Tables.Rows.ItemArray.GetValue(0).ToString() contains the string path: images/5/Video1/qbert.flv if (File.Exists(ds1.Tables.Rows.ItemArray.GetValue(0).ToString())) { //code to execute } ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.