none
How to read listitem anonymous page using client object model in sharepoint 2010 C# ? RRS feed

  • Question

  • Hi ,

           Sharepoint anonymous page read listitem using client object model C#.

    Thanks in advance

    Regards

    by

    Narasimman


    • Edited by SimhaVL Wednesday, July 10, 2019 10:32 AM
    Tuesday, July 9, 2019 3:35 PM

All replies

  • Hi,

    One ways is to elevate your privilege as shown in the below code. 

    using (ClientContext siteCollectionContext = new ClientContext("SiteCollectionURL")){
    	siteCollectionContext.Credentials = new NetworkCredential(<<ElevatedUserName>>, <<ElevatedPassword>>, <<ElevatedDomain>>);
    	List spList = siteCollectionContext.Web.Lists.GetByTitle("<<List>>");
    	CamlQuery query = new CamlQuery();
    	query.ViewXml = string.Format("<<Some Filter Condition>>");
    	Microsoft.SharePoint.Client.ListItemCollection itemCollection = spList.GetItems(query);
    	siteCollectionContext.Load(itemCollection);
    	siteCollectionContext.ExecuteQuery();                
    }
    Please remember to mark the replies as answers if they help.

    Tuesday, July 9, 2019 3:50 PM
  • Hi,

    As Giridharan's reply, we can use NetworkCredential method withe username and password to pass the credentials.

    In SharePoint 2010, I suggest you use Server Object Model with SPSecurity.RunWithElevatedPrivileges method to achieve it.

    https://docs.microsoft.com/en-us/dotnet/api/microsoft.sharepoint.spsecurity.runwithelevatedprivileges?view=sharepoint-server

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Wednesday, July 10, 2019 2:24 AM
    Moderator
  • Hi Dennis

             Thanks for you help.but i want client object model passing networkcredential not read list item in sharepoint 2010.

    Regards

    by

    Narasimman

    Wednesday, July 10, 2019 10:35 AM
  • Hi Dennis

              Thanks for your reference portal url.

    Regards

    by

    Narasimman

    Wednesday, July 10, 2019 10:36 AM
  • Hi,

    If Dennis’s reply is helpful for you, you could mark it as answer so it would help other community members find helpful information quickly.

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Friday, July 12, 2019 1:25 AM
  • Hi 

           Sharepoint page library created on anonymous page. i create custom list maintaing username nad password on sharepoint site. sharepoint anonymous page client object model using developed custom wepart custom list get the username and password.but sharepoint anonymous page username and password not authendication not working.

    i have used the below code on client object mode custom webpart in sharepoint 2010 site.

    ClientContext context = new ClientContext("http://sharepoint/");
                    context.AuthenticationMode = ClientAuthenticationMode.Anonymous;
                    Web web = context.Web;
                    List list = web.Lists.GetByTitle("ABS");
                    CamlQuery query = new CamlQuery();
                    ListItem item = list.GetItemById(1);
                    context.Load(web);
                    context.RequestTimeout = 100000;
                    context.Load(list);
                    context.Load(item);
                    context.ExecuteQuery();
                    Microsoft.SharePoint.Client.FieldUserValue userValue = item["Username"] as Microsoft.SharePoint.Client.FieldUserValue;
                    userName = Convert.ToString(userValue.LookupValue);
                    passWord = Convert.ToString(item["Password"]);
                    Domain="SP2010DEV";
                    ClientContext context = new ClientContext("http://sharepoint/");
                    context.Credentials = new NetworkCredential(userName ,passWord ,Domain);
                    Web web = context.Web;
                    context.Load(web);
                    context.ExecuteQuery();
                    Response.redirect("http://sharepoint/SitePages/Test.aspx",false);

    Thanks in advance

    Regards

    by

    Narasimman


    Wednesday, July 17, 2019 7:05 AM
  • Hi , 

            SharePoint page library created on anonymous page. we are maintaining share point custom list username and password.

    i get the username and password to open share point site with list credential share point anonymous page.

    I cannot authendicate useraccount sharepoint page.

    ClientContext context = new ClientContext("http://sharepoint/");
                    context.AuthenticationMode = ClientAuthenticationMode.Anonymous;
                    Web web = context.Web;
                    List list = web.Lists.GetByTitle("ABS");
                    CamlQuery query = new CamlQuery();
                    ListItem item = list.GetItemById(1);
                    context.Load(web);
                    context.RequestTimeout = 100000;
                    context.Load(list);
                    context.Load(item);
                    context.ExecuteQuery();
                    Microsoft.SharePoint.Client.FieldUserValue userValue = item["Username"] as Microsoft.SharePoint.Client.FieldUserValue;
                    userName = Convert.ToString(userValue.LookupValue);
                    passWord = Convert.ToString(item["Password"]);
                    Domain="SP2010DEV";
                    ClientContext context = new ClientContext("http://sharepoint/");
                    context.Credentials = new NetworkCredential(userName ,passWord ,Domain);
                    Web web = context.Web;
                    context.Load(web);
                    context.ExecuteQuery();
                    Response.redirect("http://sharepoint/SitePages/Test.aspx",false);

    Thanks in advance

    regards

    by

    Narasimman




    Wednesday, July 17, 2019 12:03 PM
  • Just make sure the SharePoint objects you access are anonymous.

    Justin Liu Office Apps & Services MVP, MCSE
    Senior Software Engineer
    Please Vote and Mark as Answer if it helps you.

    Thursday, July 18, 2019 1:40 AM
  • Hi Justin Liu ,

                      Thanks for your reply. so i need credential based to accesses the sharepoint site uisng server (or) client object model in sharepoint 2010 site.

    Regards 

    by

    Narasimman

    Thursday, July 18, 2019 7:44 AM
  • Hi,

    Can you access the "ABS" custom list anonymous?

    In this case, we can create a visual web part and use Server Object Model with SPSecurity.RunWithElevatedPrivileges method to achieve it, then add the visual web part in the page.

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Monday, July 22, 2019 1:27 AM
    Moderator