将WebPart加载到声明性目录部分 [英] Load WebPart to Declarative Catalog Part

查看:47
本文介绍了将WebPart加载到声明性目录部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我有一个网站定义,它有一个网站页面,在此页面内,我有一个自定义控件,它将处理Webpart.因此,在此自定义控件中,我添加了一个webpartzone和一个带有声明性目录部分的catalogzone,以仅显示一个Web部件.

现在,根据此站点定义创建站点之后,如何将我的Webpart添加到可用的WebPart中?

I have a site defintion, that has a site page, and inside of this page i have a custom control that will handle the webparts. So in this custom control, i added a webpartzone and a catalogzone with a declarative catalog part to show only one web part.

Now how can i add my webpart to the webparts available, after creating a site from this site defintion?

在代码后面,通过加载Webpart(_catalogs/webparts)并实例化它?怎么样?
在aspx中,注册吗?并声明Webpart?有可能吗?

谢谢

Behind the code, by loading the webpart (_catalogs/webparts) and instantiate it? How? 
In the aspx, registering? and declaring the webpart? It's this possible?

Thanks

仅从共享点开始...

Just starting with sharepoint...

推荐答案

什么是声明性目录部分?

What is the declarative catalog part ? 

如果这是页面中的自定义部件,我建议您可以使用C#代码在页面中加载和注册Web部件:

If this is a customize part in the page, I would suggest you can use C# code to load and register web part in the page:

用于在页面中动态加载Content Editor Web部件的示例代码:

A sample code to load Content Editor web part in the page dynamically:

using (SPSite site = new SPSite("http://win2008/sites/publishing"))
{
    SPWeb web = site.RootWeb;
    SPFile page = web.GetFile("Pages/Lipsum.aspx");
    page.CheckOut();

    using (SPLimitedWebPartManager wpmgr = page.GetLimitedWebPartManager(PersonalizationScope.Shared))
    {
        Guid storageKey = Guid.NewGuid();
        string wpId = String.Format("g_{0}", storageKey.ToString().Replace('-', '_'));

        XmlElement p = new XmlDocument().CreateElement("p");
        p.InnerText = "Hello World";
        ContentEditorWebPart cewp = new ContentEditorWebPart
        {
            Content = p,
            ID = wpId
        };
        wpmgr.AddWebPart(cewp, "wpz", 0);

        string marker = String.Format(CultureInfo.InvariantCulture, "<div class=\"ms-rtestate-read ms-rte-wpbox\" contentEditable=\"false\"><div class=\"ms-rtestate-read {0}\" id=\"div_{0}\"></div><div style='display:none' id=\"vid_{0}\"></div></div>", new object[] { storageKey.ToString("D") });
        SPListItem item = page.Item;
        string content = item["PublishingPageContent"] as string;
        item["PublishingPageContent"] = content.Replace("|", marker);
        item.Update();
    }

    page.CheckIn(String.Empty);
}

更多信息:

https://blog.mastykarz.nl /programmatically-adding-web-parts-rich-content-sharepoint-2010/

谢谢

最好的问候


这篇关于将WebPart加载到声明性目录部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆