Reading xmlfile in project

  • Thread starter Thread starter Steven S
  • Start date Start date
S

Steven S

I have a Web Service which reads a xml file.
If I place it in the same direcectory where source code is
how should I then read it without using physical directory adress like
"c:\inetpub\wwwroot\mywebservive" or like "c:\xmlfiles\xmlfile".

How to get a relative reference to file in C#?

Cheers!
 
Steven,

You can get the location of the currently running assembly by calling
the static GetExecutingAssembly method on the Assembly class. Once you have
the Assembly instance, you can use the Location property to get the location
on disk (assuming that it is on the local machine, not loaded from the
network, etc, etc).

Then, you can work with that to find your file.

Hope this helps.
 
Hi ,

Take a look at Assembly. CodeBase and/or Assembly.Location
 
Steven,
Your webservice can read the xml file - assuming it is in the same place as
the .ASMX Webservice "page" with Server.MapPath("myxmlfile.xml")
Peter
 
ASP.NET (including web services) shadow copies the assemblies into a
temporary folder so if you want to find the path of your web
application where you put it (that is, the actual home of the virtual
directory) then you can't really use the GetExecutingAssembly method.
Instead you'll have to use the static HttpContextclass (in the
System.Web namespace):

string webPath = HttpContext.Current.Request.PhysicalApplicationPath;

Josh
http://www.thejoyofcode.com/
 
ASP.NET (including web services) shadow copies the assemblies into a
temporary folder so if you want to find the path of your web
application where you put it (that is, the actual home of the virtual
directory) then you can't really use the GetExecutingAssembly method.
Instead you'll have to use the static HttpContextclass (in the
System.Web namespace):

string webPath = HttpContext.Current.Request.PhysicalApplicationPath;

Josh
http://www.thejoyofcode.com/
 
Thank you!

Nicholas Paldino said:
Steven,

You can get the location of the currently running assembly by calling
the static GetExecutingAssembly method on the Assembly class. Once you
have the Assembly instance, you can use the Location property to get the
location on disk (assuming that it is on the local machine, not loaded
from the network, etc, etc).

Then, you can work with that to find your file.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Steven S said:
I have a Web Service which reads a xml file.
If I place it in the same direcectory where source code is
how should I then read it without using physical directory adress like
"c:\inetpub\wwwroot\mywebservive" or like "c:\xmlfiles\xmlfile".

How to get a relative reference to file in C#?

Cheers!
 
Back
Top