0

I'm trying to read information sitting in another wesbsite using C# and displaying the result in sharepoint 2010 web part. I read about httprequest but I'm failing to implement it. Please anyone help with simplest solution you can give.

1

You can do that via the Client Side Object Model, by referencing the below DLL's to your solution

  • Microsoft.SharePoint.Client
  • Microsoft.SharePoint.Client.Runtime
  • Microsoft.SharePoint.Client.ServerRuntime

The above DLL's located at C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\

CSOM C# Code

using (ClientContext context = new ClientContext("http://yourserver/")) {
    context.Credentials = new NetworkCredential("user", "password", "domain");
    List list = web.Lists.GetByTitle("your list");

    CamlQuery query = new CamlQuery();
    query.ViewXml = "<View><RowLimit>10</RowLimit></View>";
    ListItemCollection listItems = list.GetItems(query);
    context.Load(list);
    context.Load(listItems);
    context.ExecuteQuery();

   // Load your data t gridview
   DataTable table = new DataTable();
   table.Columns.Add("Title");
   foreach (ListItem item in items)
     table.Rows.Add( item["Title"]);
   Gridview.DataSource = table;
}

Note: it's important to set the NetworkCredential parameters correctly, also you can add this info in the web config, then read it from there!

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.