简体   繁体   中英

Troubles on getting data from a List sharepoint 2013

Im having some troubles when i try to retrieve data from a list in sharepoint 2013.

  SPSite osite = new SPSite(@"http://win-kee1pn6mrku");

  SPWeb web = osite.OpenWeb();

  SPList list = web.Lists["Calendar"];
  SPListItemCollection collection = list.Items;

  foreach (SPListItem item in collection)
  {
      Console.WriteLine(item["Title"]);
  }

And im getting this error: error

I did a research in MSDN and i could connect to a diferent list in SharePoint 2010 using Visual Studio 2010, but now im using Visual Studio 2012 to connect to SharePoint 2013 and i dont get the same result.

Im using the DLL Microsoft.SharePoint.

Thanks!

i think there is something wrong when you declare the SPSite, maybe you don't need @, so:

SPSite osite = new SPSite("http://win-kee1pn6mrku");

But, I usually using:

string siteURL = SPContext.Current.Web.Url;
SPSite oSite = new SPSite(siteURL);

Hope this helps.

You could take a look at this article too:

http://social.msdn.microsoft.com/Forums/en-US/1e939d9c-0fbb-44bf-9af1-a37594d2041a/differences-between-spcontextcurrentsiteurl-and-spcontextcurrentweburl

If you are trying to get this data from client side, you should use the Microsoft.SharePoint.Client DLLs. For communicating with SharePoint 2013 you probably should get those files from the server, because the aren't yet available in a NuGet Package.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM