MOSS 2007 文档库事件处理

本文介绍了一个使用C#实现的SharePoint列表事件处理程序。该程序会在列表项被插入时,将特定字段的数据同步到SQL Server数据库中。涉及的技术包括SharePoint API、SQL Server连接及命令执行等。

using System;
using System.Text;
using Microsoft.SharePoint;
using System.Data.SqlClient;
namespace EventHandle
{
    public class listEventHandle : IListEventSink
 {
        public void OnEvent(SPListEvent listEvent)
        {

            try
            {
                if (listEvent.Type == SPListEventType.Insert)
                {
                    SPWeb web = listEvent.Site.OpenWeb();
                    SPFile SharePointEventItem = web.GetFile(listEvent.UrlAfter);
                    SPListItem item = SharePointEventItem.Item;

                    string itemid = item.ID.ToString();
                    string name = item["姓名"].ToString();
                    string destAdd = item["目的"].ToString();
                    string appDate = item["申请日期"].ToString();
                    string memo = item["备注"].ToString();
                    string email = item["Email"].ToString();
                    string cfd = item["出发地"].ToString();
                    string mdd = item["目的地"].ToString();
                    SqlConnection conn = new SqlConnection("Data Source=moss;Initial Catalog=test;integrated security=SSPI");
                    conn.Open();
                    SqlCommand cmd = new SqlCommand("insert into t_cs(listitem_id,Name,destAdd,appDate,memo,email,cfd,mdd) values('" + itemid + "','" + name + "','" + destAdd + "','" + appDate + "','" + memo + "','" + email + "','" + cfd + "','" + mdd + "')", conn);
                    cmd.ExecuteNonQuery();
                    conn.Close();
                }
            }
            catch (Exception e)
            {
                System.IO.StreamWriter log = new System.IO.StreamWriter(@"d:\log.txt", true);
                log.Write("StackTrace:" + e.StackTrace);
                log.Write("Message:" + e.Message);
                log.Flush();
                log.Close();
            }
        }
 }
}

转载于:https://www.cnblogs.com/willpower/archive/2008/07/20/1247189.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值