Pass Document credentials in C# Code

I am using following code to download SharePoint Document(Word) library and its working fine. However whenever i am trying to open this downloaded document, its keep asking document credentials.

using (ClientContext context = new ClientContext("<Site URL>"))                 {                     string filePath = @"Local Path";                     context.Credentials = new NetworkCredential("username", "Password", "domain");                     context.RequestTimeout = 6600000;                     Web web = context.Web;                     Microsoft.SharePoint.Client.List list = web.Lists.GetByTitle("<Doc Library>");                      ListItem listItem = list.GetItemById(1);                     context.Load(listItem);                     context.ExecuteQuery();                     Microsoft.SharePoint.Client.File file = listItem.File;                     context.Load(file);                     context.ExecuteQuery();                      var fileRef = file.ServerRelativeUrl;                     var fileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(context, fileRef);                     var fileName = Path.Combine(filePath, (string)listItem.File.Name);                     using (var fileStream = System.IO.File.Create(fileName))                     {                         fileInfo.Stream.CopyTo(fileStream);                     }  } 

Once I download the document, I am going to fetch content inside the documents with the help of "Microsoft.Office.Interop.Word.Application" API. Here I am getting all the content.

Microsoft.Office.Interop.Word.Application application = new Microsoft.Office.Interop.Word.Application(); ImpersonateUser iU = new ImpersonateUser(); iU.Impersonate("domain", "username", "Password"); doc = application.Documents.Open(@"LocalPath"); 

But each time its asking credentials. So would like to pass these credentials through C# code?How to do?


Category: sharepoint server Time: 2016-07-31 Views: 2

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C), All Rights Reserved.

processed in 0.283 (s). 12 q(s)