[英]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. 我在尝试从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. 我在MSDN上进行了研究,可以使用Visual Studio 2010连接到SharePoint 2010中的其他列表,但是现在我使用Visual Studio 2012连接到SharePoint 2013,但我没有得到相同的结果。
Im using the DLL Microsoft.SharePoint. 我正在使用DLL Microsoft.SharePoint。
Thanks! 谢谢!
i think there is something wrong when you declare the SPSite, maybe you don't need @, so: 我认为在声明SPSite时出了点问题,也许您不需要@,所以:
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 http://social.msdn.microsoft.com/Forums/zh-CN/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. 如果尝试从客户端获取此数据,则应使用Microsoft.SharePoint.Client DLL。 For communicating with SharePoint 2013 you probably should get those files from the server, because the aren't yet available in a NuGet Package.
与SharePoint 2013通信时,您可能应该从服务器获取这些文件,因为NuGet包中尚不提供这些文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.