471,337 Members | 879 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Reading xmlfile in project

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!
Jan 10 '06 #1
6 1623
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]
- mv*@spam.guard.caspershouse.com

"Steven S" <st*****@mymail.com> wrote in message
news:dq**********@nyytiset.pp.htv.fi...
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!

Jan 10 '06 #2
Hi ,

Take a look at Assembly. CodeBase and/or Assembly.Location

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Steven S" <st*****@mymail.com> wrote in message
news:dq**********@nyytiset.pp.htv.fi...
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!

Jan 10 '06 #3
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

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Steven S" wrote:
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!

Jan 10 '06 #4
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.PhysicalApplicationPat h;

Josh
http://www.thejoyofcode.com/

Jan 10 '06 #5
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.PhysicalApplicationPat h;

Josh
http://www.thejoyofcode.com/

Jan 10 '06 #6
Thank you!

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2******************@TK2MSFTNGP10.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Steven S" <st*****@mymail.com> wrote in message
news:dq**********@nyytiset.pp.htv.fi...
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!


Jan 11 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Juan Galdeano | last post: by
4 posts views Thread by Arvind P Rangan | last post: by
12 posts views Thread by jcrouse | last post: by
reply views Thread by rosydwin | last post: by

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.