Sharepoint 如何创建“;发布图像&x201D;以编程方式创建站点列?

Sharepoint 如何创建“;发布图像&x201D;以编程方式创建站点列?,sharepoint,Sharepoint,如何在FeatureActivated方法中以编程方式创建具有“发布图像”内容类型的站点列 我需要将此网站列添加到Microsoft.Sharepoint.Publishing中所有这些内容类型的列表中。所以我需要引用这个库。并添加此代码 public override void FeatureActivated(SPFeatureReceiverProperties properties) { using (var rootWeb = properties.Feature.Parent

如何在FeatureActivated方法中以编程方式创建具有“发布图像”内容类型的站点列


我需要将此网站列添加到Microsoft.Sharepoint.Publishing中所有这些内容类型的列表中。所以我需要引用这个库。并添加此代码

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
    using (var rootWeb = properties.Feature.Parent as SPWeb)
    {
        if (rootWeb == null)
        {
            return;
        }
        const string testSiteColumn = "TestSiteColumn";
        if (!rootWeb.Fields.ContainsField(testSiteColumn))
        {
            var newImageField = new ImageField(rootWeb.Fields, "Image", testSiteColumn)
                {
                    Group = "Test",
                    StaticName = "Test",
                    Title = "Test",
                    RichText = true,
                    RichTextMode = SPRichTextMode.FullHtml
                };
            rootWeb.Fields.Add(newImageField);
        }
    }
}
这个ContentType不在SPFieldType中,所以我需要将新ImageField中的类型硬编码为“Image”

很好