Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 231731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:57:28+00:00 2026-05-11T19:57:28+00:00

I have a WPF application which saves its data to XML files in a

  • 0

I have a WPF application which saves its data to XML files in a relative-to-code directory called “Data”.

I get the relative path to the Data directory with these methods:

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";
    }
}

This works for testing since the Debug or Relates .exe will go back up into the project and access the data.

Problem #1 with this is it doesn’t work when saving the XML file, I get a “URI formats are invalid” error, it seems it can’t deal with the “……\” part of the path when saving:

xmlDoc.Save(FullXmlDataStorePathAndFileName);

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 .xml files need to be in the same directory as the .exe or one lower in a Data directory so that each instance of the application can read and write to its own XML files.

What is the best solution for this? Requirements are:

  • 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”, so while developing, the base data is always refreshed when press F5

  • 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 paths in the .exe point to the XML files upon starting

Has anyone developed a good solution to having a local XML data source in a relative directory like this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T19:57:28+00:00Added an answer on May 11, 2026 at 7:57 pm

    You could have your xml path in a separate config file?

    Or you can use conditionals (#if DEBUG / #endif) to have separate logic for your debug version.

    But I would recommend a more appropriate place for such data, something like (system disk)\Users\UserName\AppData\Roaming\AppName(etc). If your app is installed in Program Files, then your app would need additional permissions to save files there. In Vista, this would mean you would have to run your app with raised privileges, even if your account is admin (with UAP enabled).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple WPF application in which I am using data binding
We have a WPF application which gets data from an Analysis Services Cube. The
Please help! Background info I have a WPF application which accesses a SQL Server
I have a simple WPF application which I am trying to start. I am
I have written code to save an image which is generated by the application.
I have a WPF application which is displaying field validation messages by implementing the
I have a usercontrol in my wpf application which is causing a stackoverflowexception to
I have a WPF application in VS 2008 with some web service references. For
I have a WPF application that runs fine under XP as an administrator. When
I have a WPF application using Aero Glass. When using the application under a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.