question

AlexHotianovich-0609 avatar image
0 Votes"
AlexHotianovich-0609 asked MichaelHan-MSFT commented

ProjecServer 2016 and a CSOM project in Visual Studio

Hi,
We have setup our SharePoint 2016/ProjectServer on-premise environment and we use NTLM to connect to the site. I installed Microsoft.SharePointOnline.CSOM and try to get the list of published projects. But always get 401(Unauthorized) status code.

string url = "http://url";
string username = "username";
string password = "password";

ProjectContext clientContext = new ProjectContext(url);

SecureString securestring = new SecureString();
password.ToCharArray().ToList().ForEach(s => securestring.AppendChar(s));

clientContext.Credentials = new NetworkCredential(username, securestring, "domain");

clientContext.Load(clientContext.Projects);
clientContext.ExecuteQuery();

Could you please let me know how we can solve this authorization issue?

Thanks for your help.

office-sharepoint-server-development
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

MichaelHan-MSFT avatar image
0 Votes"
MichaelHan-MSFT answered MichaelHan-MSFT commented

Hi @AlexHotianovich-0609 ,

Per my test, this works for me. How did you username like in the code? In domain\name format? If so, you do not need to add domain in NetworkCredential.

You can change your code like the below:

 string url = "http://url";
 string username = "contoso\\administrator";  //note use double slash
 string password = "password";
    
 ProjectContext clientContext = new ProjectContext(url);
    
 SecureString securestring = new SecureString();
 password.ToCharArray().ToList().ForEach(s => securestring.AppendChar(s));
    
 clientContext.Credentials = new NetworkCredential(username, securestring);
    
 clientContext.Load(clientContext.Projects);
 clientContext.ExecuteQuery();


If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi
It's not work for me. I still get error

string url = "http://project-test/PWA";
string username = @"es\essp";

0 Votes 0 ·

Hi,

Please make sure the user has enough permissions on the site.

And you could try to set the credential like this: clientContext.Credentials = new NetworkCredential(username, password);

0 Votes 0 ·

I set credential as you said. The result is the same (401)
User has admin permissions on ProjectServer.

0 Votes 0 ·
Show more comments