Ah yes, Ive had a lot of trouble with this error. If messing with
the user permissions doesnt help, there is another (more
awkward) way that works. It seems that permissions wont let
you overwrite the file if the ASP.NET didnt create it to begin with.
To overcome this, set a breakpoint on the doc.Save line. When
this is reached, delete the original file, then continue the code.
The new file will be saved, and then it can be overwritten by the
app.