Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Friday, January 18, 2013 11:11 AM
i have an xml file in my project
C:\Documents and Settings\.\.\SampleXML\SampleXML\sample.xml
if i try to load this file, it is looking at C:\Documents and Settings\.\.\SampleXML\SampleXML\bin\Debug
can u help me how to load from first location which i have mentioned
All replies (7)
Friday, January 18, 2013 11:48 AM ✅Answered | 1 vote
Add these characters “../” in front of you file name, based on the folder structure. This will navigate from bin folder, in your case the code will be as
XDocument doc = XDocument.Load(@"../../sample.xml");
first set will navigate from debug to bin, send set will navigate from bin to root folder. The root will have the xml file.
sri
Friday, January 18, 2013 11:13 AM
hi you can do like this way,
1) You can open properties and copy to Output directory =true,
2) or manually place file in debug,
By Sanz. -- If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
Friday, January 18, 2013 11:14 AM
Hi,
You mean to add XML file to your project which is present in the given path C:\Documents and Settings\.\.\SampleXML\SampleXML\bin\Debug ?
PS.Shakeer Hussain
Friday, January 18, 2013 11:15 AM
i dont want to place dat file in Debug folder.. it should be in project path which i have mentioned
XDocument doc = XDocument.Load(@"sample.xml"); \ this is looking at bin debug folder.
Friday, January 18, 2013 11:47 AM
var parent = System.IO.Directory.GetParent(Environment.CurrentDirectory); var x = XDocument.Load(parent.Parent.FullName + "\\sample.xml");
This is what you need to do
By Sanz. -- If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
Friday, January 18, 2013 12:06 PM
Hi,
If I were you I would not start with figuring out a relative path, what happens when you want to move the executable or the xml file ?
I would make the default file path an application setting you configure in the app.config or give the user the opportunity to select the file using an open filedialog
Hope this helps,
Here to learn and share. Please tell if an answer was helpful or not at all. This adds value to the answers and enables me to learn more.
Friday, April 20, 2018 2:15 PM
Nice. never knew such shortcut exist.