0

The following code works in a console application but returns a 401 error from a workflow code activity. The aim is to download and process a .eml file from a Sharepoint 2013 document library. SP and WF both reside on the same server.

System.Net.WebException: The remote server returned an error: (401) Unauthorized. at System.Net.HttpWebRequest.GetResponse() at ActivityLibrary2.CodeActivity1.Execute(CodeActivityContext context)

WebRequest request = WebRequest.Create(Url);
request.UseDefaultCredentials = true;
request.PreAuthenticate = true;
request.Credentials = CredentialCache.DefaultCredentials;
WebResponse response = (WebResponse)request.GetResponse();

I've also tried DefaultNetworkCredentials, specifying credentials, same result. The workflow app pool account has full access to the site.

Is there a better approach?

0

I ended up creating a WCF service for this code using DefaultNetworkCredentials.

I had to grant "NT AUTHORITY\network service" access to the document library.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.