Click here to Skip to main content
13,552,926 members
Rate this:
Please Sign up or sign in to vote.
See more:
When I deploy a project, the project fails on creating XML files. It works fine in Visual Studio. It says they are read only when it's deployed.

Here is what I have for one of the two xml file generators:

void write_pstest_file()
            XDocument pstest_file = new XDocument(
                new XElement("testmenu",
                new XElement("showwebhelp", "true"),
                new XElement("menuitem",
                new XAttribute("key", "ca93df85-9204-4245-a587-b63439f4a3a2"),
                    new XElement("includefile", "picoTMS.pstest")
            pstest_file.Save("C:\\Program Files (x86)\\Pico Technology\\PicoScope6 Automotive\\test.pstest");

How can I make these non read-only so they can be created once the app is deployed? Google sites are of no-help. :(
Posted 8-Oct-12 10:22am
SAKryukov 8-Oct-12 16:49pm
The question is: how they are read-only? What do you want to do with them?
joshrduncan2012 8-Oct-12 16:51pm
When I click submit on the entire program, I get an "Unhandled exception" of "System.UnauthorizedException" access to the path is denied. All I want to do is write this XML file to this particular directory. This code as is cannot be processed on a deployed instance, only works on Visual Studio itself.
Dave-Kreskowiak 8-Oct-12 17:07pm
Visual Studio has nothing to do with it. It works on your machine because you're running the app as under an admin level account.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You cannot store writable files to any folder under Program Files in Windows Vista and above.

You have to pick a more suitable place to store your writable files. Read:

Environment.GetFolderPath Method[^]
Environment.SpecialFolder Enumeration[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04-2016 | 2.8.180515.1 | Last Updated 8 Oct 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100