Ah yes, I've had a lot of trouble with this error. If messing with
the user permissions doesn't help, there is another (more
awkward) way that works. It seems that permissions won't let
you overwrite the file if the ASP.NET didn't 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.