When I am using the complete url, I get "cannot get contact site at specified url". When just the parent url like https://mydomain.sharepoint.com, then list item is created on on a list of main site address. Can anyone please help locate the desired site list content? Any help would be much appreciated. Please see code below:

string sharePointSiteUrl = "https://mydomain.sharepoint.com/site/test_site/Lists/list_items/AllItems.aspx"; // this is the complete address of already created list items. 
    using (ClientContext clc = new ClientContext(sharePointSiteUrl))
        SecureString passWord = new SecureString();
        foreach (char c in "mypassword".ToCharArray())     passWord.AppendChar(c);
        clc.Credentials = new SharePointOnlineCredentials("myuserid", passWord);
        clc.AuthenticationMode = ClientAuthenticationMode.Default;

        List oList = clc.Web.List.ContentTypeExistsByName("List_name");
        ListItemCreationInformation listCreationInformation = new ListItemCreationInformation();
        ListItem oListItem = oList.AddItem(listCreationInformation);
        oListItem["Title"] = "Add item in SharePoint List using CSOM";
        Console.WriteLine("item added successfully");
catch (Exception ex)
    Console.WriteLine("Error Message: " + ex.Message);

1 Answer 1


Your sharePointSiteUrl variable should be only the site URL where the list is located, not the URL of the default list view of the list or the URL of the root site/site collection.

Your variable assignment should look like this: string sharePointSiteUrl = "https://mydomain.sharepoint.com/site/test_site";.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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