在上一篇中,笔者介绍了如何使用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 "我的文档"
            SPList spList = spWeb.Lists[DocLibName];
            //add the node into treeview by calling the method
            tvTreeCatalog.Nodes.Add(CreateNodeByList(spList));
     }

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

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

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

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

 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号