Thursday, July 30, 2009

I am writing an ASP.NET application and I get the below error when trying to load an xml file?

with readXml method.





Could not find file 'C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\File.xml





The File.xml file is in the same project directory as default.aspx


This has to do with relative path? How do I configure it to automatically look in its same directory for the xml file?

I am writing an ASP.NET application and I get the below error when trying to load an xml file?
I would suggest performing some kind of directory look up before loading the file, and then assigning the correct path to the xml file before trying to open it. In C#, it is something liek 'CurrentDirectory.GetCurrentDirectory()" or something like that. Anyway, you can either get the directory the project is in, or, you can assign the directory path statically, then concatenate to the file path for the xml. Hope this helps...
Reply:Just to expand a little on quantumkev's answer...





The path to your project directory can be accessed by using the static HttpRuntime.AppDomainAppVirtualPath property in .NET; however, the .NET folks have taken it one step further and allowed you to use the tilde [~] key as a shortcut/placeholder for the above property. Example:





dataSet.ReadXml("~/File.xml"); // C#


dataSet.ReadXml("~/File.xml") // VB





This code will search for the xml file in the root directory of your application, which should be where your Default.aspx resides.

cvs

No comments:

Post a Comment