Click here to Skip to main content
15,893,722 members
Please Sign up or sign in to vote.
1.00/5 (1 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:

C#
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
Comments
Sergey Alexandrovich Kryukov 8-Oct-12 16:49pm    
The question is: how they are read-only? What do you want to do with them?
--SA
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

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[^]
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900