Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# XML file Writing
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 11:22am
Comments
Sergey Alexandrovich Kryukov at 8-Oct-12 16:49pm
   
The question is: how they are read-only? What do you want to do with them?
--SA
joshrduncan2012 at 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 at 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
good
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[^]
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 195
1 ProgramFOX 130
2 Maciej Los 105
3 Sergey Alexandrovich Kryukov 85
4 Afzaal Ahmad Zeeshan 82
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,717
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web02 | 2.8.1411022.1 | Last Updated 8 Oct 2012
Copyright © CodeProject, 1999-2014
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