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;
listItem.Update();
try
{
context.ExecuteQuery();
}
catch (System.Exception ex)
I get the same error. So how do I fix this?
Credentials
usingcontext.Credentials = new NetworkCredential("user", "password", "domain");