title: What is the best relative-path solution for developing/deploying WPF apps with local XML stores?
body: <p>I have a WPF application which saves its data to XML files in a <strong>relative-to-code</strong> directory called "Data".</p>
  
  <p>I get the <strong>relative path</strong> to the Data directory with these methods:</p>
  
  <pre><code>protected string ApplicationPath
  {
      get { return System.IO.Path.GetDirectoryName(System.Reflection.Assembly
            .GetExecutingAssembly().CodeBase); }
  }
  
  protected string ApplicationDataPath
  {
      get { return ApplicationPath + @"..\..\..\Data\"; }
  }
  
  public string FullXmlDataStorePathAndFileName
  {
      get
      {
          return ApplicationDataPath + GetItemTypeIdCode() + ".xml";
      }
  }
  </code></pre>
  
  <p>This works for testing since the Debug or Relates .exe will go back up into the project and access the data.</p>
  
  <p>Problem #1 with this is it doesn't work when saving the XML file, I get a "<strong>URI formats are invalid</strong>" error, it seems it can't deal with the "......\" part of the path when saving:</p>
  
  <pre><code>xmlDoc.Save(FullXmlDataStorePathAndFileName);
  </code></pre>
  
  <p>Problem #2 is that when I want to deploy my app (e.g. make it available for download so someone unzips and double-clicks on the .exe), then the <strong>.xml files need to be in the same directory as the .exe</strong> or one lower in a Data directory so that each instance of the application can read and write to its own XML files.</p>
  
  <p><strong>What is the best solution for this?</strong> Requirements are:</p>
  
  <ul>
  <li><p>XML files should be locally under the project and transparent when developing and testing, e.g. edit the XML files in Visual Studio and "Copy to Output Directory" is "Copy if Newer", <strong>so while developing, the base data is always refreshed when press F5</strong></p></li>
  <li><p>a straight-forward way of e.g. zipping up the "Release" directory and all of the files (.exe and original XML files) are there and the <strong>paths in the .exe point to the XML files upon starting</strong></p></li>
  </ul>
  
  <p><strong>Has anyone developed a good solution to having a local XML data source in a relative directory like this?</strong></p>