I'd like to save an xml file to the MyDocuments folder on the local filesystem. To do so, I use the following:
xmlDoc.Save(Path.GetPathRoot(savePath + saveName));
Where savePath
is
String qnPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "QuesitNote\\");
String savePath = Path.Combine(qnPath, "SavedDecks");
and saveName
is a string
inputted by the user, formatted to have no spaces.
I've been unable to do this because of issues with administrative rights. So far, I've tried a host of solutions, including the following:
- Change user type in the manifest file
- Use attributes to try to create an authorization function that saves the file using admin rights
- Create a separate console procedure (a whole other program altogether) that requires admin rights in the manifest file and then tries to save the xml file
The first method worked, but I only want admin rights for a particular method, the one in which I save the xml file.
The second one gave me a System.Security.SecurityException
.
And the third appears to work, but does not actually create the file, only giving a "success" message I created. The UAC prompt never came up.
At this point, I have no idea how to fix this. Ideally, I would be able to use administrative rights for only one method (using my second attempt), but a fix for the third attempt would also be helpful. How would I get the UAC prompt to appear (third attempt), or otherwise fix my way of going about this?