In my .Net application I am using Windows Authentication. I need to save a document to SharePoint, and to do this I need to use the Client Object Model with the Microsoft.Sharepoint.Client namespace. However I am getting an exception:

Microsoft.SharePoint.Client.ServerUnauthorizedAccessException: Access denied.

You do not have permission to perform this action or access this resource.

In order to fix this I am attempting to set the credentials, but the following code does not work;

       using (var context = new ClientContext(this.SharepointServer))
            context.Credentials = CredentialCache.DefaultNetworkCredentials;
            var list = context.Web.Lists.GetByTitle(this.DocumentLibrary);
            var fileCreationInformation = new FileCreationInformation
                                                  Content = file,
                                                  Overwrite = true,
                                                  Url = fileName
            var uploadFile = list.RootFolder.Files.Add(fileCreationInformation);
            var listItem = uploadFile.ListItemAllFields;
            catch (System.Exception ex)

I get the same error. So how do I fix this?

  • Try to explicitly setting the Credentials using context.Credentials = new NetworkCredential("user", "password", "domain"); Dec 18, 2014 at 15:06
  • I do not have the password as I am using windows authentication
    – arame3333
    Dec 19, 2014 at 7:27

2 Answers 2


By default, the managed client object models authenticate users by using their Windows credentials (DefaultCredentials).

So you don't need to explicitly set the Credentials.

You do not have permission to perform this action or access this resource.

This error happens when the current logged in user don't have permission to the resources. In your case the current user don't have permission to upload files to the Document Library.


You can simply add your credentials in Credential Manager under Windows Credentials. It will authenticate the site without giving the actual credential in the code.

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.