Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Including Files in Projects and FilePaths

Including Files in Projects and FilePaths

Scheduled Pinned Locked Moved C#
questionannouncementcsharpc++debugging
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    STW
    wrote on last edited by
    #1

    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

    K 1 Reply Last reply
    0
    • S STW

      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

      K Offline
      K Offline
      Kant
      wrote on last edited by
      #2

      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 the FileInfo 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".

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups