I am trying to upload a document from an ASP.NEt website (not an App) to a SharePoint library and using CSOM. This is an on premise sharepoint 2013, not office 365. Below is the code to upload the document. This works great if we run from visual studio. However, gets an access denied when we run on website. It might have something to do with the authentication. enter code here

 private void UploadFile()
        CamlQuery Query = new CamlQuery();
        Uri x = new Uri("http://testportal.com/sites/test");

        ClientContext ctx = new ClientContext(x);
        ctx.Credentials = System.Net.CredentialCache.DefaultCredentials;
        var file = "C:\\Users\\spalakollu\\Documents\\Training.vsd";
        List<string> all = new List<string>();
        using (var fs = new FileStream(file, FileMode.Open))
            var fi = new FileInfo(file);
            string ListToUtilze = string.Empty;

            var list = ctx.Web.Lists.GetByTitle("Documents");
            var fileUrl = string.Format("{0}/{1}", list.RootFolder.ServerRelativeUrl, fi.Name);

            Microsoft.SharePoint.Client.File.SaveBinaryDirect(ctx, fileUrl, fs, true);

  • Does the account running the Application pool have write permissions on your target SharePoint site?
    – Choggo
    Feb 2, 2015 at 18:53
  • That worked! Is it a best practice to have a user account for app pool identity or can we stick with ApplicationPoolIdentity?
    – svp
    Feb 2, 2015 at 20:34

1 Answer 1


Make sure that the account running the process has the required permissions in SharePoint.

Regarding the question in your comment, I am not aware of any documented best practice regarding having an actual account running the application pool. I, however, can see it as a best practice since you have better control of WHO can do WHAT in SharePoint. It also makes it easier to track down requests made by your .NET application in the SharePoint log files.

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.