晚上部署SHAREPOINT站点时,一直无法把WEBPART部件部署上去。

反复卸载,安装还是无法完成。没有看安装日志。
出错信息摘录如下:
功能“f6e0a6d7-7b0f-4a76-a3da-d434c2e8b869”未安装在此服务器场中,无法添加到该范
围。
“sztelecom.bluechannel.sanxin.webparts.wsp
”或 ID“27135f2f-9be3-4a76-86ce-63adbd89a2d2”的解决方案。
C:\Documents and Settings\administrator.SZBC\桌面\bushu\install0422\install0422\
Debug(0422_1423)\Debug\SZTelecom.BlueChannel.SanXin.WebParts.wsp: 此解决方案安装
失败。


已将解决方案“sztelecom.bluechannel.sanxin.webparts.39.196/”。请使用 force 参数重新部署此解决方案。

心情不好,最后采用了手工部署:
1.0 将DLL放到GAC中
2.0 web.config里写SafeControl 
3.0 在WEB部件管理面板中,上传相应的WEBPART文件。

参考文章:
 

当然最直接的方法,就是手动部署
  把dll放到bin或者gac -> web.config里写SafeControl -> 在网站集的web部件库中添加进来

命令行部署:通过stsadm工具部署的几种方法

方法一: 2003时代延续的方法N
  使用cab包将webpartdlldwpmanifest.xml打包成一个cab
  使用stsadm -o addwppack 部署
  (可以使用stsadm -o enumwppacks浏览这样部署的webpart —WWW.ITCHINA8.COM1u'X!O


{;n$Nw(s
    使用stsadm -o deletewppack卸载)
  这种方法也可以适用于新的webpartasp.net的),编写.webpart文件代替.dwp文件
  不过需要注意的是这两种文件的格式是不一样的,详细的就不说了,可以在web部件库里打开一个看看就知道了

方法二:moss里对方法一的改进—WWW.ITCHINA8.COM


re'[I3@5R"0f
  这个方法我没有试过,不过看起来和方法一是一致的,不过多了一些参数
  使用的是stsadm -o deploywppack部署,stsadm -o retractwppack卸载


mE|k)^0方法三:通过solution部署Z%"3['F([V
i
  需要编写一个solution用的manifest.xml,和2003时代的那个manifest.xml很像部署webpart的话,需要在里面写上AssembliesDwpFiles(资源文件的ClassResources是在Assembly里)
  其实solutionwsp文件就是cab文件,只不过是换了一个扩展名而已………………
V w{C
w%R/E~


c0  在SDK里有具体的格式说明,不过需要注意的是,sdk在这个地方有一个错误:在DwpFile节中,sdk中说使用FileName属性指定dwp/webpart文件,而实际上,应该使用Location属性替代FileName属性
部署方法(2步):stsadm -o addsolution —WWW.ITCHINA8.COMoli}7R


N%W
                          stsadm -o deploysolution 
卸载方法(2步):stsadm -o retractsolution
                          stsadm -o deletesolution
%B


R!z2D`0
方法四:通过solution + feature部署
1q


]2y


gw4E!j _a0  这是最复杂的一种方法,vs2005扩展包中的webpart模版使用的就是这种方法
  它并不是直接将webpart加到solution中,而是将其先加到一个feature中(在feature中包含dwp/webpart,并指定部署到web部件库),然后再把这个feature加到solution中(dll文件还是在solution里指定),部署的时候除了部署solution外,还需要激活那个feature
  这种方法比较灵活,可以在页面上通过feature来开启/关闭这个webpart
  部署方法(3步):stsadm -o addsolution
                          
  stsadm -o deploysolution—WWW.ITCHINA8.COM5d"D


o [m‑k
                         
   stsadm -o activatefeature
  卸载方法(4步):stsadm -o deactivatefeature
g0                            stsadm -o uninstallfeature
                         
   stsadm -o retractsolution
                         
   stsadm -o deletesolution
7q9M^Ew


g*d0  如果是通过vs2005部署的话,我们可以看到在bin"DebugRelease目录中生成wsp文件的同时,还生成了一个setup.bat,通过这个bat,就可以非常方便地完成上述步骤:
部署:setup -i—WWW.ITCHINA8.COM


M-|B+U_3|*Z
c1N
卸载:setup -u

o?6c%e""0注:VS2005装一个VS Extensions for SharePoint之后有一个项目类型模版叫做webpart,写一个webpart,然后F5,就会把webpart部署到你的SharePoint的站点中。实际上也是部署了一个Feature. 其原理MSDN上也有介绍:Walkthrough: Creating a Basic SharePoint Web Part
8r J*F}4|


X0引用通告地址: http://www.webplat.net/trackbacks.asp?tbID=124

Posted Chatterley :
WebPart对于学习和研究SharePoint的人,已经不是什么新鲜的概念了。但对于学习.net Framework的人,可能会发现在System.web.ui.webcontrols下会发现多了WebPart的踪影。WebPart作为WebControl中的一种,比WebControl更高级一些,它可以在线Drag and Drop,并可以在线设置它的属性。
以前利用VS2003开发WebPart,得安装WebPart Template For VSNet。当然也可以在VS2005下安装WebPart Template来开发WebPart。在这里我就不介绍用WebPart Template For VSNet来开发WebPart了。

在VS2005下就可以不用安装WebPart Template来开发WebPart。下面我具体介绍其过程:
1、创建 Web Control Library
首先浏览C# Project Templates,然后选择Web Control Library,输入“SampleControl”。
要开发WebPart用于SharePoint,就必须引用Microsoft.SharePoint.dll(必须是安装MOSS的服务器上的)。
最后添加引用如下图:


2、编写WebPart的代码
你开发的WebPart,根据自己开发的功能选择相应的SP(SharePoint)命名空间,具体命名空间,请参考SDK。
开发WebPart必须继承WebPart类。

//--------------------------------------------------------------------
// File: SimpleWebPart.cs
//
// Purpose: A sample Web Part that demonstrates how to create a basic
// Web Part.
//--------------------------------------------------------------------

using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint.Utilities;
using System.Web.UI.HtmlControls;

namespace Xdian.WebParts.SampleControl
{
    
/// <summary>
    
/// This Web Part changes it's own title and implements a custom property.
    
/// </summary>

    [XmlRoot(Namespace = "MyWebParts")]
    
public class SimpleWebPart : WebPart
    
{
        
private const string defaultText = "hello";
        
private string text = defaultText;

        
// Declare variables for HtmlControls user interface elements.
        HtmlButton _mybutton;
        HtmlInputText _mytextbox;

        
// Event handler for _mybutton control that sets the
        
// Title property to the value in _mytextbox control.
        public void _mybutton_click(object sender, EventArgs e)
        
{
            
this.Title = _mytextbox.Value;
            
try
            
{
                
this.SaveProperties = true;
            }

            
catch
            
{
                Caption 
= "Error Could not save property.";
            }

        }


        
// Override the ASP.NET Web.UI.Controls.CreateChildControls 
        
// method to create the objects for the Web Part's controls.      
        protected override void CreateChildControls()
        
{
            
// Create _mytextbox control.
            _mytextbox = new HtmlInputText();
            _mytextbox.Value 
= "";
            Controls.Add(_mytextbox);

            
// Create _mybutton control and wire its event handler.
            _mybutton = new HtmlButton();
            _mybutton.InnerText 
= "Set Web Part Title";
            _mybutton.ServerClick 
+= new EventHandler(_mybutton_click);
            Controls.Add(_mybutton);
        }


        [Browsable(
true), Category("Miscellaneous"),
        DefaultValue(defaultText),
        WebPartStorage(Storage.Personal),
        FriendlyName(
"Text"), Description("Text Property")]
        
public string Text
        
{
            
get
            
{
                
return text;
            }


            
set
            
{
                text 
= value;
            }

        }


        
protected override void RenderWebPart(HtmlTextWriter output)
        
{
            RenderChildren(output);
            
// Securely write out HTML
            output.Write("<BR>Text Property: " + SPEncode.HtmlEncode(Text));
        }

    }

}

3、编写WebPart定义文件(.dwp)
这个文件是xml文件,任意文本文件更改其扩展名为.dwp就可以了。
我的WebPart的程序集文件为SampleControl.dll。命名空间为Xdian.WebParts.SampleControl。所以我的SampleControl.dwp文件如下:

<?xml version="1.0"?>
<WebPart xmlns="http://schemas.microsoft.com/WebPart/v2">
   
<Assembly>SampleControl, Version=1.0.0.0, Culture=neutral,PublicKeyToken=0e79ac0ff7e9e2cb</Assembly>
   
<TypeName>Xdian.WebParts.SampleControl.SimpleWebPart</TypeName>
   
<Title>SampleWebPart</Title>
   
<Description>Chatterley Create The first WebPart</Description>
</WebPart>

4、生成强名称程序集合
在这点,我在VS2005下,没有找到解决方法,因为在C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin下没有sn.exe这个工具了。
我跑到VS2003的机子下,在cmd下浏览到VS2003下的bin目录。用sn.exe随机生成了一个key.snk。输入sn.exe -h可以看参数。然后在项目文件下的Assembly.cs下加入这么一行文字:
[assembly: AssemblyKeyFile(@"C:\key.snk")]
我是把key.snk放在C:盘下的。最后生成的程序集,可以通过sn.exe -Tp来参看其PublicKeyToken。我采用的方法是用gacutil.exe放入C:/Windows/Assembly下,然后看去属性中的PublicKeyToken。

最终生成的程序集和配置文件如下:


5、修改WebConfig。
我想大家肯定会在那么多的Config混乱,你就把它放入你想添加WebPart到的SharePoint网站下。如下我把它放如8000端口的网站下(某个GUID网站下)。

当然你也可以把你的WebPart放如全局上,那么你就得修改C:\Program Files\Common Files\Microsoft Shared\web server extensions下的相应文件(不推荐)。

在WebConfig下,添加如下的配置信息:

<SafeControls>
<SafeControl Assembly="SampleControl, Version=1.0.0.0, Culture=neutral,PublicKeyToken=0e79ac0ff7e9e2cb"     Namespace="Xdian.WebParts.SampleControl"     TypeName="*"  Safe="True"/>
</SafeControls>

6、添加WebPart到网站的WebPart Gallery中。
你必须要有网站管理员的权限。进入http://vsts01:8000/下的网站管理。在WebPart管理的列表中,点击“上载”。浏览到我的SampleControl.dwp,然后输入配置信息,上传。最后在WebPart Gallery显示一条信息如下:



7、把WebPart添加到网页显示。
进入编辑网页。找到自己的SampleControl,然后添加(和SPS2003的操作有所不同)。
最后终于把WebPart显示在自己的网站上,不过不要开发太多的WebPart,网站对WebPart的承受能力是有限的。一个网站大概可以承受100个WebPart左右。如果你的网站超过的话,那么你的网站速度会明显变慢。

posted on 2008-04-23 02:28  大鱼  阅读(539)  评论(0编辑  收藏  举报