Including Files in Projects and FilePaths
-
I've included an XML File into my project. In a class I open this file with the following FilePath:"..\\..\\XmlFile.xml". That's right because the application folder is the bin\debug folder but the Xml File is in the project folder. But what is if I want to install my project? Then the Xml File will be in the application folder but in my class the folder stays "..\\..\\XmlFile.xml" so the file won't be found. I hope that there is another possibily than to copy each time I compile und start the App. the XmlFile into the debug folder and change the FilePath in the class to "XmlFile.xml" to be sure to have the actual file version, right? How can I resolve this FilePath Problem? In VC++ as I remember it was possible to define debug/release preprocessor derictives to solve such problems. But how in C#? Thanks Stefan
-
I've included an XML File into my project. In a class I open this file with the following FilePath:"..\\..\\XmlFile.xml". That's right because the application folder is the bin\debug folder but the Xml File is in the project folder. But what is if I want to install my project? Then the Xml File will be in the application folder but in my class the folder stays "..\\..\\XmlFile.xml" so the file won't be found. I hope that there is another possibily than to copy each time I compile und start the App. the XmlFile into the debug folder and change the FilePath in the class to "XmlFile.xml" to be sure to have the actual file version, right? How can I resolve this FilePath Problem? In VC++ as I remember it was possible to define debug/release preprocessor derictives to solve such problems. But how in C#? Thanks Stefan
STW wrote: In a class I open this file with the following FilePath:"..\\..\\XmlFile.xml". Instead of using that way, why don't you the keep file in the bin\debug. The better way is select the file via
OpenFileDialog
. Use theFileInfo
class so that you can check that file exist or not.FileInfo fileInfo = new FileInfo(fileName); if(fileInfo.Exists) { .. }
STW wrote: But what is if I want to install my project? Then the Xml File will be in the application folder but in my class the folder stays "..\\..\\XmlFile.xml" so the file won't be found. If you have already got the Deployment project in your solution. Then just add the XML file to that project and make sure that the 'Folder' property of that file is set to "Application Folder". (Properties window)_
Never take a problem to your boss unless you have a solution._
This signature was created by "Code Project Quoter".