Hopefully, if you are getting an UnauthorizedAccessException in IIS 6 while trying to write out a file this will help you.
Today a client was frustrated after rolling out an application from staging to live. The web application created thumbnails on the fly and caches those thumbnails to disk using a FileStream. The code worked fine in the dev environment and in the staging environment, but as soon as it went to the live server it started throwing an UnauthorizedAccessException whenever the file was being written.
After searching Google for the terms in this posts subject I finally came across what I thought might fix the problem, sure enough it did. The IIS_WPG group must have the correct rights in the folder you are trying to write files to.
---------------------- Snip of the error -------------------
UnauthorizedAccessException: Access to the path '[THE_PATH_WAS_HERE]' is denied.]
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +2013027
System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) +998
System.IO.FileStream..ctor(String path, FileMode mode) +65