473,719 Members | 2,033 Online
Bytes | Software Development & Data Engineering Community
+ 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\www root\mywebservi ve" or like "c:\xmlfiles\xm lfile".

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

Cheers!
Jan 10 '06 #1
6 1691
Steven,

You can get the location of the currently running assembly by calling
the static GetExecutingAss embly 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.co m

"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\www root\mywebservi ve" or like "c:\xmlfiles\xm lfile".

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.Locati on

--
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\www root\mywebservi ve" or like "c:\xmlfiles\xm lfile".

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\www root\mywebservi ve" or like "c:\xmlfiles\xm lfile".

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 GetExecutingAss embly method.
Instead you'll have to use the static HttpContextclas s (in the
System.Web namespace):

string webPath = HttpContext.Cur rent.Request.Ph ysicalApplicati onPath;

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 GetExecutingAss embly method.
Instead you'll have to use the static HttpContextclas s (in the
System.Web namespace):

string webPath = HttpContext.Cur rent.Request.Ph ysicalApplicati onPath;

Josh
http://www.thejoyofcode.com/

Jan 10 '06 #6
Thank you!

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:%2******** **********@TK2M SFTNGP10.phx.gb l...
Steven,

You can get the location of the currently running assembly by calling
the static GetExecutingAss embly 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.co m

"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\www root\mywebservi ve" or like "c:\xmlfiles\xm lfile".

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
1211
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 xmlDoc As XmlDocument Private Sub Zadig_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim xmlTr As New XmlTextReader(xmlFile)
1
2365
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 users can be connected at the same time, the user information in the file can also be changed by other programs, like an administration application. So my xmlfile needs to be updated as soon as any application changes a value and it needs to reflect...
0
1780
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 System.Xml.Schema.DtdParser.ScanDtdContent() at System.Xml.Schema.DtdParser.ParseDtdContent() at System.Xml.Schema.DtdParser.ParseDocTypeDecl()
3
1154
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 problem when its readonly access to the file? I mean do i need some kind of lock on the method so only one thread can access it? My thougt was that i would have a problem if the methid should
0
1274
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: ds.ReadXml("xmlfilepath\xmlfile.xml", XmlReadMode.Auto) Here is an example of an element in the xml file: <item> <title>Newark Valley Fathers Day Challenge</title>
4
1035
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 xmlreads.NodeType Case XmlNodeType.Element If InStr(xmlreads.Name, "id") > 0 Then
12
1485
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" myXmlTextWriter.WriteElementString("Height", InputBoxHeight myXmlTextWriter.WriteElementString("Width", InputBoxWidth 'myXmlTextWriter.WriteElementString("Background", (OpenFileDialog1.FileName) myXmlTextWriter.WriteElementString("label1.Top", label1.Top...
1
1569
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 code. Please help............ private static XmlSchemaCollection schema_collection_object; private static XmlSchema m_ifschema;
3
1909
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 xmlreq = false; //xmlreq =document.implementation.createDocument("","",null); xmlreq = new ActiveXObject("Microsoft.XMLDOM"); var xmlFile="/val/valid.xml"; var vale=""; xmlreq.async="false"; xmlreq.onreadystatechange=verify();
0
8828
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8725
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9360
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7993
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6658
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5971
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3185
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 we have to send another system
2
2562
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2124
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.