Skip to main content
 首页 » 编程设计

c#之如何使用客户端对象模型检索呈现的 Sharepoint WebPart 数据

2024年01月01日47zlslch

我正在尝试使用客户端对象模型从 Sharepoint 2010 站点远程访问数据。对于某些限制,我无法使用 CAML 查询,即使我使用我也无法根据用户登录过滤适当的受众(如果你能帮助我了解 CAML 查询也很好::我不知道如何获取当前用户受众名称和所有使用 CAML/客户端对象模型的受众。此代码位于移动站点上并调用共享点站点,如我的代码所示)。以下代码运行良好,但无法从 Web 部件获取内容。有人可以帮忙解决这个问题吗?

    using (ClientContext ctx = new ClientContext("https://mysite.com/Pages/Default.aspx")) 
      { 
                 ctx.ExecutingWebRequest += new EventHandler<WebRequestEventArgs>   (clientContext_ExecutingWebRequest);     
 
                 File home=ctx.Web.GetFileByServerRelativeUrl("/Student/Pages/default.aspx");                       
             //get the web part manager 
                     Microsoft.SharePoint.Client.WebParts.LimitedWebPartManager wpm = home.GetLimitedWebPartManager(Microsoft.SharePoint.Client.WebParts.PersonalizationScope.Shared); 
 
                IEnumerable<Microsoft.SharePoint.Client.WebParts.WebPartDefinition> wpds = null; 
             //create the LINQ query to get the web parts from 
             //the web part definition collection 
                wpds = ctx.LoadQuery(wpm.WebParts.Include(wp => wp.Id,wp => wp.WebPart));  
             //load the list of web parts 
                ctx.ExecuteQuery(); 
             //enumerate the results 
                foreach (Microsoft.SharePoint.Client.WebParts.WebPartDefinition wpd in wpds) 
                { 
                   string title=  wpd.WebPart.Title; 
                   Microsoft.SharePoint.Client.WebParts.WebPart wpart = wpd.WebPart;      
 
                  ????? How to render and receive the data (looking for the same data When you browse the site with the browser)       
                } 
 
              Code continues... 

请您参考如下方法:

我也在纠结这个问题。看起来这对于客户端对象模型来说真的是不可能的。事实上,我已经在 2012 年 Build Conference 上向一些 SharePoint 工作人员询问过。

但是,使用 SharePoint Designer 实际上可以下载所需的 WebPart。 Fiddler 可能会派上用场,以追踪哪些服务将为您提供数据。

看看这篇文章here on SharePoint StackExchange

不幸的是,该帖子不会为您提供任何具体的解决方法。

祝你好运!