473,468 Members | 1,423 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 1677
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: fremenusul | last post by:
First let me say I am familar with programming, but not familiar with VB.net. I am loading an existing XML document with this procedure Dim xmlFile As String = "..\data\Products.xml" Dim...
1
by: Niklas Lagergren | last post by:
Hi, I'll try to explain. I'm now using C# and I have an xmlfile that contains users and information about them, this xmlfile can be read and changed from many threads in my application, as many...
0
by: Juan Galdeano | last post by:
Hi, I'm working on an ONIX project and when I try to validate or read XML files C# gives me this exception: System.IndexOutOfRangeException at System.Xml.XmlScanner.ScanDtdContent() at...
3
by: Flare | last post by:
H I have a dll lib wich contains a static method to read and return a result from a xmlfile. But is possible that this dll could be called at the same time from muliple threads. Is this a...
0
by: Kathryn | last post by:
Hello, I am trying to read an xml file into a web page via vb.net. I am current using an rss format and reading it directly into a DataSet with the following command:...
4
by: Arvind P Rangan | last post by:
Hi, Code: Dim xmlstring As String = "http://localhost/log.xml" Dim xmlreads As XmlTextReader = New XmlTextReader(xmlstring) Dim id As Integer = 0 Try While xmlreads.Read() Select Case...
12
by: jcrouse | last post by:
I am using the following code to write to an XML file myXmlTextWriter.Formatting = System.Xml.Formatting.Indente myXmlTextWriter.WriteStartElement("CPViewer"...
1
by: hemendravyas | last post by:
Please help out in following code snippet: For the first time it gives prompt while XmlSchema.Read(). Second time schema_collection_object is not null and so does not enter into this block of...
3
by: shareme | last post by:
hi I am trying to get xml values into javascript I have been trying to get xml values through javascript and it is working fine in IE but not in firefox. here are the javascript code var...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.