[Favorite]How to Add a Webpart to a Site Definition Page

Source: http://weblogs.asp.net/jan/archive/2004/12/21/329107.aspx

Suppose you’ve created a webpart, which is so cool that you want to have it on every page of your SharePoint site. A nice way to accomplish this is to create your own site definition, which contains your webpart on every page. Does this sound like rocket science? Trust me, it isn’t and I’ll prove it to you. :-) In fact I was a little bit scared of site definitions at first, but once you get used to them they can become very handy! First of all, if you need to learn the basics of creating site definitions, take a look at following article: Creating a Site Definition from an Existing Site Definition.  In this example I’ll modify the site template for a SharePoint Portal site, but you can do the same thing for a Windows SharePoint Services site definition as well. A best-practice is to leave the default site definitions untouched, but on your development box you could choose to alter them anyway to get you started quickly. Just make sure you’ve got a copy, just in case…

 

You can find the Portal site definition in C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\TEMPLATE\1033\SPS. The 1033 number corresponds with the language of your Portal site definition (1033 is English), SPS corresponds with what kind of page you want to modify (SPS is the Portal stuff, STS is WSS stuff). So let’s open the default.aspx page, but do not open the page by using http://localhost/default.aspx for example, instead open it directly from the SPS folder (otherwise you’d end up with an un-ghosted page). The first thing you need to do is adding the following line to the top of the page:

<%@ Register TagPrefix="WpNs0" Namespace="SuperWebParts" Assembly="SuperWebParts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" %>

Next you need to find the place in the page where you want to insert your webpart. Once you’ve found you’re spot, insert following lines:

<WpNs0:MySuperWebPart runat="server" >

<WebPart xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/WebPart/v2">

  <Title>My Super WebPart</Title>

</WebPart>

</WpNs0:MySuperWebPart>

Notice that the WpNs0 schema reference corresponds with the one you’ve chosen in the Register TagPrefix line at the top of the default.aspx page. Finally save your page and check out the result in a browser.

 

In the <WebPart> node you can specify additional properties for your webpart, for example following lines will display your webpart without title bar.

<WebPart xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/WebPart/v2">

  <Title>My Super WebPart2</Title>

  <FrameType>None</FrameType>

</WebPart>

 

To find out which values you can use inside the <WebPart> element, is to drag-and-drop your webpart on a site the normal way (inside your webrowser); apply all the desired modifications by using the tool pane (click the down arrow and choose “Modify Shared Web Part”). When you’re done click the Apply button so your changes get applied, then click the down arrow in your web part toolbar and choose “Export…”.  This file contains the <WebPart> xml node which you can copy/paste in your default.aspx page. Quite handy isn’t it?

 

One final tip to find the place in the default.aspx page where you want to insert your webpart: open the portal/site page in FrontPage (warning: do not save the page because you’ll end up with an un-ghosted page!!). Then choose the Split view (bottom left) and click the area in which you want to display your webpart. The corresponding lines will be highlighted in the code view! Once again: do not change the page in FrontPage!

If you want to get into site definitions, I highly recommend following articles:

posted @ 2005-02-05 11:43 dudu 阅读(831) 评论(1)  编辑 收藏 网摘 所属分类: SharePoint

  回复  引用    
#1楼 2006-02-23 15:14 | kehao [未注册用户]
科昊仪表公司是一个专业的<a href="httP://www.kehaoauto.com.cn">温控器,无纸记录仪,PID调节仪,流量积算仪,工业调节器,巡检仪</a>产品生产厂家,主要产品有">httP://www.kehaoauto.com.cn">温控器,无纸记录仪,PID调节仪,流量积算仪,工业调节器,巡检仪</a>产品生产厂家,主要产品有:智能工业调节器,PID调节仪,比例调节仪,流量积算仪,32路,48,64路,多路巡仪,液晶,流量,无纸,显示,记录仪,手操器,多路灯式报警仪,频率转速表,可控硅触发,湿度传感器,压差控制器,温度传感器,温度控制柜及DCS现场总线型等
详细请浏览我公司网站<a href="httP://www.kehaoauto.com.cn" title="温控器,无纸记录仪,PID调节仪,流量积算仪,工业调节器,巡检仪">httP://www.kehaoauto.com.cn</a>





标题  
姓名  
主页
Email (博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
Google站内搜索

China-pub 计算机图书网上专卖店!6.5万品种 2-8折!
近千种 9-95 新二手计算图书火热销售中!
开发者征途系统新作:《设计模式——基于C#的工程化实现及扩展》

相关文章:

相关链接: