本文介绍了我可以通过编程方式将“搜索Web部件"添加到共享点页面吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个程序,将webParts添加到共享点页面,如下所示:

 公共 无效 AddWebPart(字符串 siteUrl,字符串 WebPartName,字符串 ZoneID, int  ZoneIndex,字符串 pageURL)
       {
           SPSecurity.RunWithElevatedPrivileges(委托()
           {
           SPSite mySiteCollection =  SPSite(siteUrl);

           SPWeb w = mySiteCollection.OpenWeb();

           //  SPFile f = w.GetFile("pages/" + pageName +".aspx"); 

           SPFile f = w.GetFile(pageURL);

           SPLimitedWebPartManager wpm = f.GetLimitedWebPartManager(System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);

           SPList l = w.Lists [WebPartName]; // 仅可以在此处添加列表和库中的Web部件

           ListViewWebPart wp =  ListViewWebPart();

           wp.​​ListName = l.ID.ToString("  B" ).ToUpper();

           wp.​​ViewGuid = l.DefaultView.ID.ToString("  B" ).ToUpper();

           wpm.AddWebPart(wp,ZoneID,ZoneIndex);
            });
       }




我希望添加除列表和库"中列出的WebPart之外的WebPart.只要在网站或网站集上启用了所需的任何基础功能.


I have created a program to add webParts to sharepoint page as follows :

public void AddWebPart(string siteUrl, string WebPartName, string ZoneID, int ZoneIndex, string pageURL)
       {
           SPSecurity.RunWithElevatedPrivileges(delegate()
           {
           SPSite mySiteCollection = new SPSite(siteUrl);

           SPWeb w = mySiteCollection.OpenWeb();

           //SPFile f = w.GetFile("pages/" + pageName + ".aspx");

           SPFile f = w.GetFile(pageURL);

           SPLimitedWebPartManager wpm = f.GetLimitedWebPartManager(System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);

           SPList l = w.Lists[WebPartName];      //Only the webparts in the Lists and Libraries can be added here

           ListViewWebPart wp = new ListViewWebPart();

           wp.ListName = l.ID.ToString("B").ToUpper();

           wp.ViewGuid = l.DefaultView.ID.ToString("B").ToUpper();

           wpm.AddWebPart(wp, ZoneID, ZoneIndex);
            });
       }




I wish to add a webpart other than the ones that are listed in ''Lists and Libraries''.

解决方案


这篇关于我可以通过编程方式将“搜索Web部件"添加到共享点页面吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 12:28