整合SharePoint文档库与讨论板功能实现文档讨论板

     公司提出要对SharePoint文档库里的公司月刊做讨论,我在网上下了个文档库讨论板,结果安装的时候出错不能用,也不想去改了,发现SharePoint里自带的讨论板挺好的,于是就决定把文档库和讨论板结合起来,结果效果还不错。其实没什么技术含量的啦,只是觉得想法还不错,拿出来分享一下。

     那就说说想法吧。

     1、创建个文档库,创建个讨论板,在文档库里添加个字段,类项 “超链接或图片”,用做点击讨论。

                                                                                     

     2、写个Event Feature, 在ItemAdded里添加代码,让在添加文档的时候,在讨论区添加每个文档的讨论板,修改“超链接或图片”字段,不过在修改“超链接或图片”字段时需要注意,在值中的逗号后需要加个空格。

                                             

     3、代码:

           public override void ItemAdded(SPItemEventProperties properties)
        {
            base.ItemUpdated(properties);
            try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPSite site = new SPSite(properties.SiteId))
                    {
                        using (SPWeb web = site.OpenWeb(properties.RelativeWebUrl))
                        {
                            SPList list = web.Lists[properties.ListId];
                            if (list.Title == "公司月刊")
                            {
                                SPListItem item = list.GetItemById(properties.ListItemId);
                                if (list.Fields.ContainsField("发表评论"))
                                    if (item["发表评论"] == null)
                                    {   //添加每个文档讨论板,在讨论主题里把文档名称,及相关说明放进去。
                                        string discussionUrl = addDiscussion(site, item["名称"].ToString(), item["创建时间"].ToString());
                                        item["发表评论"] = discussionUrl + ", 发表评论";//需要注意逗号后空格
                                        this.DisableEventFiring();
                                        item.Update();
                                        this.EnableEventFiring();
                                    }
                            }
                        }
                    }
                }
                 );
            }
            catch (Exception)
            { }
        }
        private string addDiscussion(SPSite spSite, string listItemTitle, string itemTime)
        {
            string lstr_ret = "";
            try
            {
                SPList spDiscussion = spSite.RootWeb.Lists["月刊讨论"];
                SPListItem discussionItem = spDiscussion.Items.Add();
                discussionItem["Title"] = listItemTitle;
                discussionItem["正文"] = "欢迎发表您对 " + itemTime.Substring(0,8) + "电子月刊: " + listItemTitle + " 的观点!";
                discussionItem.Update();
                lstr_ret = spSite.RootWeb.Url + "/" + discussionItem.Url;
            }
            catch (Exception)
            {
                return lstr_ret;
            }
            return lstr_ret;
        }
    }

下载地址:https://files.cnblogs.com/windy2008/MagazineEventHandle.rar
原文地址:http://www.cnblogs.com/windy2008/archive/2009/03/20/1417948.html

posted on 2009-03-20 19:40  欣静赏悦  阅读(2467)  评论(6编辑  收藏  举报