MOSS下面WEBPART开发小结

    接触MOSS(Microsoft Office Sharepoint Server)平台,发觉它很好很强大。具体的工作流还没有用过,只是在里边,发布了几个WEBPART,并布署单点登陆等等。需要的操作系统环境比较麻烦,后面会搞台虚拟机自己安装一遍。

    利用quickpart(开源 quickpart下载地址:http://quickpart.codeplex.com/)封装ASCX来发布WEBPART,开发效率与以前的ASPX页面开发没有什么区别。下载QUICKPART包以后,执行InstallSolution.bat批处理,进行安装解决方案,完成后,在WSS3.0管理中心中,操作--解决方案管理下边,可以找到  quickpart.wsp  然后点击该解决方案,进行布署,我这边布署的是所有Web 应用程序,也可以布署到有需要用到的WEB应用程序.

    要用新建网站制作ASCX(不能创建ASP.NET应用程序,因为,不能直接发布单个程序集,如果要发布单个程序集要写发布脚本,没深入研究过)开发WEBPART的生产者与消费者,示例代码如下:(通过接口进行数据传递)

   

   

ContractedBlock.gif ExpandedBlockStart.gif Code
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

/// <summary>
/// Summary description for ItestIft
/// </summary>
public interface Itestitf
{
    
string getname();
    
string gethost();
}

 

生产者(数据发送者)ASCX.CS代码如下:

 

ContractedBlock.gif ExpandedBlockStart.gif Code
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Microsoft.SharePoint;




public partial class myWebCtrl : System.Web.UI.UserControl, Itestitf
{



    
protected void Page_Load(object sender, EventArgs e)
    {      
        
if (!this.IsPostBack)
        {
            
this.TextBox1.Text = myString;
        }
    }

    [WebBrowsable(
true), Personalizable(true), WebDescription("txt"), WebDisplayName("显示的内容")]
    
public string myString
    {

        
get { return this.TextBox1.Text; }
        
set {  this.TextBox1.Text = value; }

    }

    [ConnectionProvider(
"sendmystring")]
    
public Itestitf SendMyString()
    {
        
return this;
    }

    
protected void Button1_Click(object sender, EventArgs e)
    {


        myString 
= this.Context.User.Identity.Name;
       
// this.TextBox1.Text = "22";
        this.SendMyString();
    }
    
protected void Button2_Click(object sender, EventArgs e)
    {
        
this.SendMyString();
    }

    
#region Itestitf Members

    
public string getname()
    {
       
// throw new NotImplementedException();
        return myString;
    }

    
public string gethost()
    {
        
return "testwsspc";
    }

    
#endregion
}

 

消费者(数据接收者)ASCX.CS代码如下:

 

ContractedBlock.gif ExpandedBlockStart.gif Code
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Microsoft.SharePoint;

public partial class ReciveCtrl : System.Web.UI.UserControl
{
   

    
protected void Page_Load(object sender, EventArgs e)
    {
        
this.Label1.Text = mystr;
    }

    
protected string mystr
    {
        
get;
        
set;
    }

    [ConnectionConsumer(
"sendmystring")]
    
public void ReceiveMyString(Itestitf str)
    {
        
this.Label1.Text = str.getname()+";"+str.gethost();

    }

}

 

数据读取与显示并分页的话,参考http://www.cnblogs.com/jianyi0115/archive/2008/04/03/1136816.html

我自己用的代码如下,记录一下,以备日后参考:

 

ContractedBlock.gif ExpandedBlockStart.gif Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Data;
using System.Collections;

public partial class UserControls_WorksAloneList : System.Web.UI.UserControl
{
    
protected void Page_Load(object sender, EventArgs e)
    {
        

        
try
        {
           
            ObjectDataSource odsDataSource 
= new ObjectDataSource();
            odsDataSource.ID 
= "QuerySource";
            odsDataSource.TypeName 
= this.GetType().FullName + "," + this.GetType().Assembly.FullName;
            odsDataSource.SelectMethod 
= "GetDataTable";
            Parameter p 
= new Parameter("obj", System.TypeCode.Object);
            odsDataSource.SelectParameters.Add(p);
//SelectMethod 有参数传递时
            odsDataSource.Selecting += new ObjectDataSourceSelectingEventHandler(this.Objectdatasource1_Selecting);
           

            Controls.Add(odsDataSource);

            
//{0}表示过滤值,{1}表示过滤字段值
            SPGridView1.FilteredDataSourcePropertyFormat = "{1}='{0}'";
            SPGridView1.FilteredDataSourcePropertyName 
= "FilterExpression";

            SPGridView1.EnableViewState 
= false;
            
//排序
            SPGridView1.AllowSorting = true;

            
//过滤
            SPGridView1.AllowFiltering = true;

            SPGridView1.FilterDataFields 
= "Mean,GroupID,FromTip,ImportLevelID,isRepeat,RequestFinishTime";

//如果有些列表字段不过滤,也要用","分隔,例:"Mean,,,ImportLevelID,isRepeat,RequestFinishTime";

            
this.SPGridView1.DataSourceID = "QuerySource";    
            
         
//   BindGV();

        }
        
catch (Exception ex)
        { Response.Write(ex.Message 
+ Environment.NewLine + ex.StackTrace); }

     
//   }
    }


    
public ComplaintOrderQuery coQuery;
    

    [ConnectionConsumer(
"sendcoQuery")]
    
public void ReceiveComplaintOrderQuery(IComplaintOrderSearch iCos)
    {
        
try
        {
            
this.coQuery = iCos.GetComplaintOrderQuery();

            
if (coQuery != null)
            {
                
this.SPGridView1.DataBind(); 
            }
        }
        
catch (Exception ex)
        { Response.Write(ex.Message 
+ Environment.NewLine + ex.StackTrace); }

    }
 
  

    
public DataTable GetDataTable(object obj)
    {
       DataTable tblData 
= new DataTable();

        ComplaintOrderQuery tempCoq  
= obj as ComplaintOrderQuery;

         tblData 
= ComplaintOrderInfoBLL.GetComplaintOrderInfoList(tempCoq);
      

         
return tblData;


    }

    
protected void Objectdatasource1_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
    {
        e.InputParameters[
0= this.coQuery;//SelectMethod 方法形参的值,因为是反射调用所以不能在GetDataTable方法中直接调用 this.coQuery
    }

 
  
}

 

完成本地的WEB站点集开发完以后,布署到生产环境的时候,使用如下方法(参考:http://www.cnblogs.com/jianyi0115/archive/2007/11/16/962036.html)

需要把测试环境中的站点完整的迁移到生产环境。

迁移步骤:

1)在测试服务器上运行以下命令,备份数据:
"C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\bin\stsadm" -o backup -url http://localhost:9031 -filename e:\share\sps-backup-9031.bak

 


2)将备份文件复制到生产服务器(主服务器)的c盘根目录。


3)在2生产服务器上部署所有扩展文件。


4)创建应用程序,不要创建站点集:

9031

5)部署资源文家,dll到站点

6)运行以下命令还原数据:


"C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\bin\stsadm" -o restore -url http://localhost:9031 -filename c:\sps-backup-9031.bak

7)测试

另,若要讲一个子站点迁移到另外的地方,可以用以下命令:
stsadm -o export -url http://moss/IT -filename c:\mossbak\IT.bak -includeusersecurity
stsadm -o import -url http://moss/IT -filename c:\mossbak\IT.bak -includeusersecurity

 

 

 


 

 

 

转载于:https://www.cnblogs.com/xiaorong/archive/2009/04/30/1446975.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值