悠闲小风专栏

SharePoint & Workflow 解决方案

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

     在上一篇中,笔者介绍了如何使用QuickPart开发一个简单的WebPart,这一部分笔者在上一篇的基础上自定义一个WebPart的属性,使得我们的WebPart可以重复使用,而不必每次站点下多了一个文档库就去开发一个WebPart,只需完善上一篇的代码即可

代码如下:

//定义文档库的名称,默认为"我的文档"

        private string _docLibraryName = "我的文档";

        //定义为私有属性,前面两项必须,后面两项只为达到友好提示目的

        [Personalizable]

        [WebBrowsable]

        [WebDisplayName("文档库名称")]

        [WebDescription("实施管理文档库")]

        //定义成属性,显示在SideBar边栏上为文本框

        public string DocLibName

        {

            get

            {

                return _docLibraryName;

            }

            set

            {

                _docLibraryName = value;

            }

      }

//main method,bind the document library

        private void BindDocLibrary()

        {

            //get the current web content,include list,listitem,folder and so on

            SPWeb spWeb = SPContext.Current.Web;

            //attention please!your document library must called "我的文档"

            //通过docLibraryName动态获取文档库

            SPList spList = spWeb.Lists[DocLibName];

            //add the node into treeview by calling the method

            tvTreeCatalog.Nodes.Add(CreateNodeByList(spList));

     }

请注意, BindDocLibrary方法只需要将原来静态绑定上去的文档库名称换成动态的docLibraryName就可以了,其余方法的代码均不需要做任何改动,重新Build项目

笔者新建了一个文档库做测试,依次网站操作”->编辑页面”->”修改共享Web部件

在页面右边的SideBar上已经出现了我们自定义的属性,文档库名称默认为我的文档

文档库名称输入您站点下的其它文档库名称,单击确定按钮

重新打开SharePoint网站,进入文档中心子站点,就可以看到如上图所示的效果了,关于如何自定义WebPart的属性至此就介绍完了

posted on 2009-03-28 12:52  陈典洪  阅读(694)  评论(0编辑  收藏  举报