1 / 13

WalkThrough SharePoint WebPart 入门指南 二

WalkThrough SharePoint WebPart 入门指南 二. blog.joycode.com. Kaneboy [MS MVP]. 转载声明:此 WalkThrough 系列被转载和引用时,请保持博客堂链接。 修改 WalkThrough 中的任何内容都需要经过许可。 Thanks. 创建一个显示指定文档库最新的文件列表的 WebPart 在 WebPart 定义可在浏览时让用户自行调整的属性 在 WebPart 中访问 SharePoint Object Model. 此 WalkThrough 将演示.

Download Presentation

WalkThrough SharePoint WebPart 入门指南 二

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. WalkThroughSharePoint WebPart 入门指南 二 blog.joycode.com Kaneboy [MS MVP] 转载声明:此WalkThrough系列被转载和引用时,请保持博客堂链接。 修改WalkThrough中的任何内容都需要经过许可。Thanks.

  2. 创建一个显示指定文档库最新的文件列表的WebPart创建一个显示指定文档库最新的文件列表的WebPart 在WebPart定义可在浏览时让用户自行调整的属性 在WebPart中访问SharePoint Object Model 此WalkThrough将演示

  3. 请通过前一辑《WalkThrough – SharePoint WebPart 入门指南》了解在VS.NET中创建WebPart的基础知识,此WalkThrough将不再对细节详细说明 背景知识

  4. 一、在VS.NET中创建一个WebPart项目 在VS.NET中创建一个“Web Part Library”项目,将项目改名为“SampleWebPart”,VS.NET会自动创建一个名称为“WebPart1”的WebPart组件(并位于名称空间“SampleWebPart”之下)。

  5. 二、创建属性 “ListName” 1、定义一个变量: private String _sListName = "共享文档"; 2、定义一个对应的属性: [Browsable(true), Category("设置"), DefaultValue(""), WebPartStorage(Storage.Personal), FriendlyName("文档库名称"), Description("要显示的文档库的名称")] public String ListName { get { return _sListName; } set { _sListName = value; } } 修饰属性的Attribute的解释 

  6. 三、创建属性 “DisplayCount” 1、定义一个变量: private UInt32 _iDisplayCount = 10; 2、定义一个对应的属性: [Browsable(true), Category("设置"), DefaultValue(10), WebPartStorage(Storage.Personal), FriendlyName("显示文件数量"), Description("可显示的文件的最大数量")] public UInt32 DisplayCount { get { return _iDisplayCount; } set { _iDisplayCount = value; } }

  7. 四、创建访问指定文档库中文件的Method private String GetListFiles() { String result = ""; if ((this.ListName != null) && (this.ListName.Length > 0)) { SPQuery query = new SPQuery(); query.Query = "<OrderBy><FieldRef Name=\"修改时间\" Ascending=\"FALSE\" /></OrderBy>"; query.RowLimit = this.DisplayCount; SPList list = SPControl.GetContextWeb(this.Context).Lists[this.ListName]; foreach(SPListItem item in list.GetItems(query)) { if (item.File != null) { result += "<li><a href='" + item.File.Url + "'>" + item.File.Name + "(" + item.File.Author.Name + ")" + "</a><br>"; } } } return result; }

  8. 五、通过RenderWebPart()输出内容 在重载的RenderWebPart()方法中通过调用第四步创建的GetListFiles()所返回的String来输出内容。 protected override void RenderWebPart(HtmlTextWriter output) { output.Write(this.GetListFiles()); }

  9. 六、将WebPart部署到服务器上 1、配置WebPart(通过修改.dwp文件); 2、使SPS服务器信任WebPart(在SPS虚拟站点的web.config文件中增加<SafeControl>段); 3、将VS.NET编译出的.dll文件拷贝到SPS虚拟站点根目录的“bin”目录中; 4、在WebPart页面上导入WebPart。 以上步骤可以参看前一辑的WalkThrough来获取更详细信息。

  10. 七、修改SPS站点的信任等级 打开SPS虚拟站点的根目录下的web.config文件,找到下面这行: <trust level="WSS_Minimal" originUrl="" /> 将其修改为: <trust level="WSS_Medium" originUrl="" /> 提示: WebPart在默认的安全等级下是无法访问SharePoint Object Model的(即无法通过WSS SDK来访问SPS站点中的列表、文档库、文档、用户等信息),为了让我们的WebPart能正常工作,我们可以: ★ 为这个WebPart创建一个单独的Policy文件 ★ 将WebPart的(.dll)文件加上StrongName后放入GAC中 ★ 提升整个SPS虚拟站点的信任等级 上面采用的是第三种方法,将默认的信任等级从WSS_Minimal提升到WSS_Medium(最高等级为Full)。

  11. 八、在页面上直接修改WebPart属性 1、我们已经可以看到导入到页面的WebPart所呈现出的效果。它按照修改时间倒序排序,列出了指定文档库中的文档。 2、点击WebPart右上角的向下箭头,并选择菜单中的“修改我的Web部件”。

  12. 八、在页面上直接修改WebPart属性 (二) 3、在出现的属性Panel中,我们可以看到我们在第二步和第三步中创建的两个属性。用户可以通过这里直接修改这些自定义属性,并影响WebPart的效果。我们将“显示文件数量”的值修改为5(也就是在第三步中定义的WebPart的DisplayCount属性)。 4、点击“确定”按钮后,页面上的WebPart将如我们所想的那样,只显示最近修改的5个文档。

  13. 九、 To Be Continue… 在以后的WalkThrough中,将陆续包含下面的内容:在WebPart中包含用Code-Behind方式写的User Control; 用(.cab)方式和Wppackager来部署WebPart; 在VS.NET中调试WebPart; 为文档库编写事件处理器…

More Related