i have few xml files in my project.i used "advanced installer" software to create exe setup files.i have included the xml files in PROJECT->BIN->RELEASE ->RESOURCES folder.
after installing the project setup,when i run the project, i am able to view the xml file details ,but i cannot add new content to the xml file,or delete field from the file..
how should the xml file be included in the project ???

please help..its urgent
thanks in advance

Dani AI

Generated

Most likely this is a permissions/installation-location issue rather than an XML API bug. When the installer drops your XML into the program folder (Program Files or the app folder under Program Files), standard users can read those files but cannot modify them without elevation. Also check for an empty catch block that might be hiding an UnauthorizedAccessException — good point from @nick_crane.

Quick checks to run inside the installed app

  • Verify the exact file path your code is opening (it may be pointing to Program Files).
  • Log or inspect File.GetAttributes(path) to see if the file is ReadOnly.
  • Test write permission explicitly instead of swallowing exceptions.

Example C# checks (paste into your save routine or a small test method):

var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources", "settings.xml");
var attrs = File.GetAttributes(path);
Console.WriteLine("Attrs: " + attrs);
try {
  using (var fs = File.Open(path, FileMode.Open, FileAccess.Write)) { /* writable */ }
}
catch (UnauthorizedAccessException ex) {
  Console.WriteLine("Write blocked: " + ex.Message);
}

Fix options (choose one based on whether data is per-user or shared)

  • Per-user data: copy the XML to a per-user folder (Environment.SpecialFolder.ApplicationData or LocalApplicationData) on first run and save there. Example: create Company\App subfolder under ApplicationData and save the XML file there.
  • Shared data: install the writable file to ProgramData (CommonApplicationData) and set Modify permissions for Users in the installer. Don’t leave user data in Program Files.
  • Alternative pattern: keep a read-only default XML in Program Files and copy it to a writable location on first run.

Also ensure Build Action = Content and Copy to Output Directory set appropriately so the installer has the right source file. Avoid relying on UAC VirtualStore — it is not a reliable fix.

Recommended Answers

All 4 Replies

Most likely this is due to file/folder security of the destination folder after installation.
To check this you need to answer the following Qs.

Do you get any errors when you try to change an XML file?
If so, what are they and where in your code do they occur?

When you have the answers you should understand why you cannot change the XML files.

thanks but i dnt get any error...just the xml file dont get updated on clicking save button..

When you run the program in both DEBUG and RELEASE from the DevEnv does everything work fine?

If the installation is on your development machine try attaching to the the running process and debugging the save operation to be certain that there are no errors that you might be ignoring with an empty catch block.

try { ... } 
catch () {}

application works fine when i run exe files in both release n debug folders..but when i deploy the application,after installation i am able to read from the xml files,but not add or delete fields.. is der any specific folder to which the xml files have to be copied during deployment?is there anything to do with build action property of these xml files?thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.