Click here to Skip to main content
15,886,638 members
Please Sign up or sign in to vote.
2.50/5 (3 votes)
See more:
Hi guys,
I have created a windows application with XML as my DB, now it works fine after creating .exe of it on my local machine but when I run that exe on other machine it gives me error,"Could not find path:My local PC path of XML file".
I have done Googling but could not find the correct path for which that exe will work on another machine as well.
Any help on this.
Thanks in Advance.
Posted
Comments
Shemeemsha (ഷെമീംഷ) 24-Sep-14 1:54am    
Which path not finding.. Have you stored any request file in your machine..
Sinisa Hajnal 24-Sep-14 2:07am    
Do not have any fixed path hard-coded into your program. You cannot know what rights your application will have on any given machine. I would suggest to use application folder as the "base of operation" and save your XML in some data folder.

Or you can use System.Environment like this:
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
System.IO.Path.Combine(Environment.GetFolderPath(
Environment.SpecialFolder.ApplicationData), "your_db.xml")
adityaswami89 24-Sep-14 2:50am    
you should do something like below :
AppDomain.CurrentDomain.BaseDirectory + @"Database.xml"
Sergey Alexandrovich Kryukov 24-Sep-14 2:52am    
No code sample, no essential detail. How anyone could help?
—SA
ZurdoDev 24-Sep-14 8:13am    
The error is clear. It can't find the file it needs.

1 solution

Read file path like this

AppDomain.CurrentDomain.BaseDirectory + "\\myxmlfile.xml"

and make sure when u are in debug mode and run this on visual studio then the xml file should available on ur debug folder along with ur .exe file.


ie, the exe and the file should be available in the sample folder
if this is available in any of the sub folder then give like this

AppDomain.CurrentDomain.BaseDirectory + "\\subfolder\\myxmlfile.xml";

Any thing else need to clarify pls let me know.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900