mardi 6 janvier 2015

Microsoft.SharePoint.Client.ServerUnauthorizedAccessException on test server but not in dev



I am trying to save a document in Sharepoint 2013 with the following code;



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;
listItem.Update();
try
{
context.ExecuteQuery();
}
catch (System.Exception ex)
{
throw ex;
}

if (this.Metadata.Count > 0)
{
this.SaveMetadata(uploadFile, context);
}

return GetSharepointFileInfo(context, list, uploadFile);
}


This throws an exception when running on the test server, but works on my local machine. I am using Windows Authentication. It may be that the application pool on the test server is running on a different account. However I can't see how to impersonate myself in order to save the document under my account. From what I can tell I need my password which is not available under windows authentication. So how do I fix this?








0 commentaires:

Enregistrer un commentaire