简体   繁体   English

在SharePoint 2010中,如何在运行时添加用户选择的WebPart?

[英]In SharePoint 2010 how can I add user selected WebParts at run time?

I am quite new to SharePoint and have been given an interesting problem to solve. 我对SharePoint还是很陌生,并且得到了一个有趣的问题来解决。 My users have requested to each have a custom home page that they can customise with ease. 我的用户已要求每个人都有一个自定义主页,他们可以轻松自定义主页。 The design I have been given is to have an almost blank page with space for 4 webparts organised in a 2 by 2 fashion (2 webparts by 2 webparts) each with a big '+' button in witch to click to select and add a widget of their choosing without having to play around with the ribbon. 我得到的设计是有一个几乎空白的页面,其中有4个webpart的空间,以2 x 2的方式组织(2 webpart x 2 webparts),每一个在女巫中都带有一个大的“ +”按钮,以单击以选择并添加小部件他们的选择而不必玩丝带。 This is expected to look something like this: 预期如下所示:

http://imageshack.us/photo/my-images/841/homepages.jpg/ http://imageshack.us/photo/my-images/841/homepages.jpg/

Now when a user clicks a '+' a SharePoint dialog is to be displayed allowing the user to choose from all available web parts. 现在,当用户单击“ +”时,将显示一个SharePoint对话框,允许用户从所有可用的Web部件中进行选择。 On selecting one the home page is refreshed and the widget is displayed in the selected zone. 选择一个后,将刷新主页,并且小部件将显示在所选区域中。

I am currently trying to de-risk this request to see if it is possible to achieve in the time frame given. 我目前正在尝试降低此请求的风险,以查看是否有可能在给定的时间内实现。 The problems I have at the moment are as follows: 我目前遇到的问题如下:

  1. Programmatically getting a list of all available webparts to display in the dialog. 以编程方式获取所有可用的Web部件的列表以显示在对话框中。
  2. On the selection of the webpart programmatically adding that chosen webpart to the correct part of the home page without hard coding the type of webpart (so the code does not need to be changed when a new webpart is added to SharePoint for users to add). 在选择Web部件时,以编程方式将所选的Web部件添加到主页的正确部分,而无需对Web部件的类型进行硬编码(因此,当将新的Web部件添加到SharePoint中以供用户添加时,无需更改代码)。

I would really appreciate any help or advice on this. 我真的很感谢在此方面的任何帮助或建议。 Thanks in advance and sorry if the question is well phrased, this is my first Stack Overflow question! 在此先感谢您,如果问题措辞得当,很抱歉,这是我的第一个堆栈溢出问题!

Just create a webpart that does that. 只需创建一个执行此操作的Webpart。 Render a big plus sign and when a user clicks there, the event handler gets all webparts available and renders it to a dropdownlist for instance. 呈现一个大加号,当用户单击该位置时,事件处理程序将使所有Web部件可用并将其呈现到下拉列表中。 The rest is easy, when a user selects one, get it (by guid/name whatever) and add it to the zone where the first webpart was present, not forgetting to remove the plus sign webpart from the clicked webpart zone first. 其余的操作很简单,当用户选择一个(通过guid / name命名)并将其添加到第一个Webpart所在的区域时,不要忘记先从单击的Webpart区域中删除加号Webpart This can be achieved using the SPLimitedWebPartManager. 可以使用SPLimitedWebPartManager来实现。

The tricky part could be the Webparts that are available on the SiteCollection, but you could research on that. 棘手的部分可能是SiteCollection上可用的Webpart,但是您可以对此进行研究。

Regards, 问候,

Pedro 佩德罗

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

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