How to set value for webpart’s properties when I create a new sharepoint template
Posted on 2006-10-31 23:00 bestcomy 阅读(1247) 评论(0) 编辑 收藏 举报When I create a new sharepoint template for my project use, I want to set the value for webpart’s properties as soon as the site created using this template. Adding a list by default is easy after my reading of the great article from http://aspalliance.com/ . I have developed a webpart for list displaying, and I know how to add this webpart in the rootweb by default, but I don’t know how to set value for the webpart’s properties by default. When I open a Onet.xml from one built-in template I got a example as follows:
2 <![CDATA[
3 <WebPart xmlns="http://schemas.microsoft.com/WebPart/v2" xmlns:iwp="http://schemas.microsoft.com/WebPart/v2/Image">
4 <Assembly>Microsoft.SharePoint, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
5 <TypeName>Microsoft.SharePoint.WebPartPages.ImageWebPart</TypeName>
6 <FrameType>None</FrameType>
7 <Title>网站图像</Title>
8 <iwp:ImageLink>/_layouts/images/homepage.gif</iwp:ImageLink>
9 </WebPart>
10 ]]>
11 </AllUsersWebPart>
I believe line 8 is the key of my problem. And now the problem is how to set the iwp prefix. After my reflector of Microsoft.SharePoint.WebPartPages.ImageWebPart, I got some interesting code fragment below:
2 public sealed class ImageWebPart : WebPart, IDesignTimeHtmlProvider, ICellConsumer
3 {
4 //

5 }
Compare xmlns:iwp="http://schemas.microsoft.com/WebPart/v2/Image" to XmlRoot(Namespace="http://schemas.microsoft.com/WebPart/v2/Image"), I know the answer. my webpart xmlroot is "Microsoft.MCS.HPITeam.Portal.WebParts", so I registered my webpart as following:
<![CDATA[
<WebPart xmlns="http://schemas.microsoft.com/WebPart/v2" xmlns:dtl="Microsoft.MCS.HPITeam.Portal.WebParts">
<Assembly>Microsoft.MCS.HPITeam.Portal.WebParts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=541eeb7342aeb9f8</Assembly>
<TypeName>Microsoft.MCS.HPITeam.Portal.WebParts.DocumentTopList</TypeName>
<FrameType>None</FrameType>
<Title>部门动态</Title>
<dtl:DocumentLibraryName>部门动态</dtl:DocumentLibraryName>
<dtl:DisplayTitle>部门动态</dtl:DisplayTitle>
<dtl:DisplayWidth>500</dtl:DisplayWidth>
</WebPart>
]]>
</AllUsersWebPart>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架