Search code examples
c#visual-studio-2015permission-denied

C# - Trying to write a XML file in the appfolder and get access denied


:)

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.


Solution

  • 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.