0

I am working on a SharePoint site, and I want to parse the owner of the site from the API. I am currently using the following code:

var credentials = new SharePointOnlineCredentials(userName, securePassword);
cc.Credentials = credentials; //cc is client context
Site web = cc.Site;
cc.Load(web);
cc.ExecuteQuery();
Console.WriteLine(web.Url);

I am occasionally getting a 503 Error when the execute query runs. Then I try to call the owner and that error persists. Do you know what causes the error and how I can get the owner of a sharepoint site through the api , either XML or Client object model?

0

You can refer the following example to the CSOM

class Program
{
    static void Main(string[] args)
    {
        Console.Write("Enter Username: ");
        string username = Console.ReadLine();
        Console.Write("Enter Password: ");
        SecureString password = GetConsoleSecurePassword();
        string url = "site url";

        ClientContext clientContext = new ClientContext(url);
        clientContext.Credentials = new SharePointOnlineCredentials(username, password);

        Site site = clientContext.Site;     
        clientContext.Load(site);
        clientContext.ExecuteQuery();

        Console.Write(site.Url);

        Console.Read();
    }

    private static SecureString GetConsoleSecurePassword()
    {
        SecureString pwd = new SecureString();
        while (true)
        {
            ConsoleKeyInfo i = Console.ReadKey(true);
            if (i.Key == ConsoleKey.Enter)
            {
                break;
            }
            else if (i.Key == ConsoleKey.Backspace)
            {
                pwd.RemoveAt(pwd.Length - 1);
                Console.Write("\b \b");
            }
            else
            {
                pwd.AppendChar(i.KeyChar);
                Console.Write("*");
            }
        }
        return pwd;
    }
}

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.