How can I allow a web part to create a file on a unc path? I have a location with ntfs permissions set to everyone\full control and am getting 'access denied' messages.

The SP2010 app pool is running as a domain account, so on that basis alone, it should work. I can set the trust level of the SP web application to full, but that seems excessive for this one task. I would prefer not to have to go to the trouble of making an out-of-process web service to get around this.

What is the correct way to handle this?

Update: Still fails with trust set to 'full'.

  • what are you writing to the file system and do you need to track who wrote it...i.e. does the write have to happen in the context of the currently logged in user?
    – Rob D'Oria
    Aug 23, 2011 at 14:34
  • No, It doesn't need to relate to the user at all. Aug 23, 2011 at 15:16

1 Answer 1


Is the UNC path location you're writing to in the same domain as the SharePoint server(s)?

If so, then I would just grant access to the app pool service account only and run your filesystem write code block with elevated privileges: SPSecurity.RunWithElevatedPrivileges

If not, then you will probably need to login as and impersonate an account within the domain hosting the UNC path location and run your filesystem write code block within the context of that account.

Either way, it's always preferable to store the content/data in a SharePoint list/library and not cross that architectural boundary if possible, but I won't harp on that too much since I can envision scenarios where that might not work (i.e. dropping a file for a mainframe batch process).

  • Yes, same domain. Your speculation regarding the batch process is not far off. This is an app operating on an external datatype and producing a file on a share. Only the UI is in Sharepoint. It doesn't really relate to any other Sharepoint content. In general, I would agree. Aug 23, 2011 at 15:48
  • In that case, try running the operation with elevated privileges and granting the app pool account for that web app explicit privileges to the UNC path location...should work.
    – Rob D'Oria
    Aug 23, 2011 at 15:50
  • I don't get how that is able to elevate beyond the WSS Minimal trust setting on the the AppPool, but working nonetheless! Aug 23, 2011 at 17:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.