简体   繁体   English

从 Sharepoint 提供程序托管的应用程序中检索 SharePoint 2013 列表数据

[英]Retrieving SharePoint 2013 List Data from Sharepoint provider hosted app

I have created a SharePoint 2013 provider hosted app using visual studio.我使用 Visual Studio 创建了一个 SharePoint 2013 提供程序托管应用程序。 It don't use the web parts.它不使用 Web 部件。 I have to retrieve the data from the SharePoint 2013 list residing on the SharePoint site collection.I can do that with visual web part by this code我必须从驻留在 SharePoint 网站集中的 SharePoint 2013 列表中检索数据。我可以通过此代码使用可视化 Web 部件来做到这一点

 private DataTable GetItemDetails()
 {
      SPWeb spweb = SPContext.Current.Web;
      SPList ticketsList = spweb.GetList("[http://git-hub/sites/mysiteName/Lists/CalendarList/AllItems]");
      return ticketsList.Items.GetDataTable();
 }

This gave me table of items and I used that table to get the required data.这给了我项目表,我使用该表来获取所需的数据。 But the problem is now I want use same data my SharePoint app which is made of asp.net pages with c# code behind.但问题是现在我想使用与我的 SharePoint 应用程序相同的数据,该应用程序由带有 c# 代码的 asp.net 页面组成。 I used the same code but it giving me error like "我使用了相同的代码,但它给了我类似“

Microsoft SharePoint is not supported in 32-bit process. 32 位进程不支持 Microsoft SharePoint。 Please verify that you are running in a 64-bit executable." Even I am using any plate form in app build settings. Please let me know if any way I can retrieve the list data in asp.net page to show the user their schedules.请验证您是否在 64 位可执行文件中运行。”即使我在应用程序构建设置中使用任何平板形式。请告诉我是否可以通过任何方式检索 asp.net 页面中的列表数据以向用户显示他们的日程安排.

you can also use Managed client object model :您还可以使用托管客户端对象模型:

Uri hostWeb = new Uri(Request.QueryString["SPHostUrl"]);
        List<string> listOfUsers = new List<string>();


        using (var clientContext = TokenHelper.GetS2SClientContextWithWindowsIdentity(hostWeb, Request.LogonUserIdentity))
        {

            List oList = clientContext.Web.Lists.GetByTitle("TestList");

            CamlQuery camlQuery = new CamlQuery();
            camlQuery.ViewXml = "<View><Query><Where><Geq><FieldRef Name='ID'/>" +
                "<Value Type='Number'>0</Value></Geq></Where></Query><RowLimit>100</RowLimit></View>";
            Microsoft.SharePoint.Client.ListItemCollection collListItem = oList.GetItems(camlQuery);

            clientContext.Load(collListItem);

            clientContext.ExecuteQuery();

            foreach (Microsoft.SharePoint.Client.ListItem oListItem in collListItem)
            {
                listview.Add(string.Format("ID: {0} \nTitle: {1}", oListItem.Id, oListItem["Title"]));
            }

            ListList.DataSource = listOfUsers;
            ListList.DataBind();

        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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