0
votes

:)

I'm trying to write an XML file in the application folder, however I keep getting the access error denied.

  1. I already have the manifest file with:

    requestedExecutionLevel level = "requireAdministrator" uiAccess = "false"

  2. I get the folder path with:

    Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

Can anyone help me? Thank you!

Ps.: Sorry for the the bad english.

-- EDIT This is the part where I try write the file.

try
{
   string caminhoXML = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
   dsGenAlys.WriteXml(caminhoXML);
}
catch (Exception ex)
{
   lbl_status.Text = "Status: Não foi possível salvar. Error: " + ex.Message;
   return;
}

I always get the labelmsg text with the Acess Denied to the folder path.

-- EDIT 2

I get this error on any path I put.

2
Welcome to Stack Overflow! Please see How to Ask for information on how to ask good questions. In this case, it is best to provide a minimal reproducible example that someone can use to replicate your situation. - Kateract
Could you also put the code which is attempting to write to this folder? - aguertin
@aguertin I edited the post with the code! :) - psc37
Try to run Visual Studio 'As Administrator'. It may solve your problem - Shai Aharoni
@ShaiAharoni same problem =/ - psc37

2 Answers

1
votes

Your problem is that you are not specifically stating a filename in the xmlWrite path. Append a name for the file and it should work.

0
votes

Solved!

With the comment of @aguertin, "The problem is actually because in your path there isn't a file name", I just use the string with a name for the file. Done!

Thank you all!