MrProgram
MrProgram

Reputation: 5242

access denied when saving xdocument

I'm using IIS and VS 2013. I'm creating a XDocument and wan't to save it into a local folder.

XDocument doc = new XDocument();
doc.Save(@"C:\temp");

This gives me "access denied on C:\temp". I've also tried with c\users\firstname.lastname but the result is the same.

I've tried giving everyone full control on both folders. Also tried giving my AppPool full control (shouldn't matter when everyone still has it?).

Does anyone have some tips?

Upvotes: 2

Views: 3916

Answers (1)

lloyd
lloyd

Reputation: 1811

You have not set a file name according to your question

doc.Save(@"C:\temp");

Should have the path and file name. It's worth checking if the file exists first

string fileName = @"C:\temp\MyNewFile.xml";
if (!File.Exists(fileName))
{
    doc.Save(fileName);
}

Upvotes: 3

Related Questions