场解决方案添加webpart(Create Webpart to page using code)
转:http://www.soaspx.com/dotnet/asp.net/tech/tech_20120814_9489.html
/// <summary>
/// 向页面添加Webpart
///
</summary>
/// <param name="web">站点</param>
/// <param name="pageUrl">页面地址</param>
/// <param name="webPartName">Webpart名称</param>
/// <param name="zoneID">WebPartZone的ID</param>
/// <param name="zoneIndex">ZoneIndex</param>
/// <param name="properties">字典类型的杂项名称和值</param>
/// <returns></returns>
public static
string AddWebPartToPage(SPWeb web,
string pageUrl, string webPartName,
string zoneID, int zoneIndex, Dictionary<string,
string> properties)
{
using (Microsoft.SharePoint.WebPartPages.SPLimitedWebPartManager webPartManager = web.GetLimitedWebPartManager(
pageUrl, PersonalizationScope.Shared))
{
using (WebPart webPart = CreateWebPart(web, webPartName, webPartManager))
{
Microsoft.SharePoint.WebPartPages.SPUserCodeWebPart codeWebPart
= webPart.WebBrowsableObject as Microsoft.SharePoint.WebPartPages.SPUserCodeWebPart;
if (properties !=
null)
{
foreach (string key
in properties.Keys)
{
foreach (Microsoft.SharePoint.WebPartPages.SPUserCodeProperty item
in codeWebPart.Properties)
{
if (item.Name == key)
{
item.Value = properties[key];
}
}
}
}
webPart.ChromeType = PartChromeType.None;//设置部件版式类型 设置 无
webPartManager.AddWebPart(webPart, zoneID, zoneIndex);
return webPart.ID;
}
}
}
public
static WebPart CreateWebPart(SPWeb web, string webPartName, Microsoft.SharePoint.WebPartPages.SPLimitedWebPartManager webPartManager)
{
SPQuery qry = new SPQuery();
qry.Query = String.Format("<Where><Eq><FieldRef Name='FileLeafRef' /><Value Type='File'>{0}</Value></Eq></Where>",
webPartName);
SPList webPartGallery = null;
if (null == web.ParentWeb)
{
webPartGallery = web.GetCatalog(
SPListTemplateType.WebPartCatalog);
}
else
{
webPartGallery = web.Site.RootWeb.GetCatalog(
SPListTemplateType.WebPartCatalog);
}
SPListItemCollection webParts = webPartGallery.GetItems(qry);
XmlReader xmlReader = new XmlTextReader(webParts[0].File.OpenBinaryStream());
string errorMsg;
WebPart webPart = webPartManager.ImportWebPart(xmlReader,
out errorMsg);
return webPart;
}
调用
Dictionary<string,
string> properity = new Dictionary<string,
string>();
properity.Add("CalendarURL",
"/SystemSetting/Lists/EnterpriseCalendar/AllItems.aspx"); CommonUtil.AddWebPartToPage(systemWeb,
"/SystemSetting/SitePages/CalendarView.aspx",
"EnterpriseCalendarViewWebPart.webpart",
"Left",
0, properity);
场解决方案添加webpart(Create Webpart to page using code)的更多相关文章
- SharePoint 2013 场解决方案包含第三方程序集
前言 当我们使用SharePoint 场解决方案的时候,经常会包含第三方的程序集,而第三方的程序集经常会有强签名的问题,如果有强签名可以部署到GAC,没有的话也可以部署到应用程序下. 那么,很多初学者 ...
- SharePoint 沙盒解决方案 VS 场解决方案
博客地址 http://blog.csdn.net/foxdave 最近看书正好看到了关于沙盒解决方案的介绍,便整理记录一下. 虽然沙盒解决方案已经在最新的SharePoint开发中被否决弃用了(被A ...
- 无法将从VSS中的解决方案添加到TFS的源代码管理器中
VSS是一种非常有用的项目文件管理工具,百度百科的解释是:VSS 的全称为 Visual Source Safe .作为 Microsoft Visual Studio 的一名成员,它主要任务就是负责 ...
- 关于hexo markdown添加的图片在github page中无法显示的问题
title: 关于hexo markdown添加的图片在github page中无法显示的问题 date: 2018-03-31 00:21:18 categories: methods tags: ...
- javascript - Get page source code - Stack Overflow
javascript - Get page source code - Stack Overflow Get page source code
- 网站集A的子网站B上没有解决方案C发布的webpart
在A的主站点,查看解决方案C在该网站集的feature,若未打开,则打开:若已经打开,可以先关闭再打开一次. 如果问题依然存在,可以查看子网站B上的feature是否打开,若未打开,则打开:若已经打开 ...
- iOS系统中导航栏的转场解决方案与最佳实践
背景 目前,开源社区和业界内已经存在一些 iOS 导航栏转场的解决方案,但对于历史包袱沉重的美团 App 而言,这些解决方案并不完美.有的方案不能满足复杂的页面跳转场景,有的方案迁移成本较大,为此我们 ...
- VS2012给同一个解决方案添加多个项目
1.选择文件->添加->新建项目或现有项目 2.接下来在解决方案资源管理器中我们会发现解决方ConsoleApplication1中有两个项目,这里一个是类库项目ClassLibrary1 ...
- SharePoint 如何导出部署的场解决方案
前言 当我们在做服务器场迁移或者备份的时候,经常需要场中部署的解决方案包,然而,很多时候,我们无法找到这些解决方案包.很多解决方案在部署的时候,可能就已经删掉了,很多解决方案由于时间久远,我们不知道哪 ...
随机推荐
- ORA-22275: invalid LOB locator specified
性能测试20行和20000行的出现错误 20行的字符没有问题,两万行的出行问题如下 [2014-02-11 09:21:03.343665][17694862] Level 0 cicmpub.C: ...
- Linux内核Radix Tree(二)
1. 并发技术 由于需要页高速缓存是全局的,各进程不停的访问,必须要考虑其并发性能,单纯的对一棵树使用锁导致的大量争用是不能满足速度需要的,Linux中是在遍历树的时候采用一种RCU技术,来实现同 ...
- 利用Keepalived+mysql构建高可用MySQL双主自动切转
转载:http://www.it300.com/index.php/article-15266.html 关于MySQL-HA,目前有多种解决方案,比如heartbeat.drbd.mmm.共享存储, ...
- 压力测试之apache benchmark
ab 的全称是 ApacheBench , 是 Apache 附带的一个小工具 , 专门用于 HTTP Server 的 benchmark testing , 可以同时模拟多个并发请求.前段时间看到 ...
- .Net 平台下的互联网架构新思考
上一篇<互联网应用架构谈>有很多阅读量,但后来实践中发现基于WCF服务层技术用于实现网站访问的效率是有问题的. 我的本意是以WCF中间层解决商业逻辑,供各个平台调用,然而还是带来诸多的麻烦 ...
- linux管道的容量和内部组织方式
1.管道容量 count=65536,即64KB #include<stdio.h> #include<sys/types.h> #include<unistd.h&g ...
- JAVA String 类
java String类中的常用方法:public char charAt(int index)返回字符串中第index个字符:public int length()返回字符串的长度:public i ...
- SDC(7) -- 关于使能信号的时序放松
先看下图: 假如使能信号的有效时间为时钟周期的2倍,此时需要使用 set_multicycle_path 放松使能信号 sel_xy_nab ,若是每个寄存器使能端都约束一遍,那就太麻烦了: 这时可以 ...
- 如何解决jenkins中shell脚本明明执行失败却不自行退出,且构建结果仍然显示success的问题??
首先,需要明确shell命令执行结果$?为0或者非0仅能代表此执行语句是否顺利执行了,例如: 执行语句:adb connect 192.168.XX.XX 执行结果:unable to connect ...
- hdu 1043 pku poj 1077 Eight (BFS + 康拓展开)
http://acm.hdu.edu.cn/showproblem.php?pid=1043 http://poj.org/problem?id=1077 Eight Time Limit: 1000 ...