如何使用功能上传发布页面?

时间:2009-02-06 09:24:27

标签: sharepoint sharepoint-2007 sharepoint-designer publishing

我正在尝试制作一个功能,可以在“页面”库中上传新的发布页面,但它不能按照我想要的方式运行。如果我使用SharePoint Designer查看库,则会显示我的发布页面,但如果我使用Internet Explorer则不会。

在我配置属性的功能中:ContentTypeId,ContentTye,Author,Title,FileRef,FileDirRef,FileLeafRef,FileType,LinkFilenameNoMenu,LinkFilename和DocIcon。在以前的功能中,我遇到了同样的问题,它解决了ContentTypeId属性。在这种情况下,我不确切地知道错误在哪里。

4 个答案:

答案 0 :(得分:1)

我使用以下代码基于页面布局创建发布页面,该页面布局被认为已经过配置并基于内容类型。代码在您的功能的FeatureActivated事件处理程序中运行:

    using (SPWeb ParentWeb = properties.Feature.Parent as SPWeb)
    {
            PublishingWeb webpublish = PublishingWeb.GetPublishingWeb(ParentWeb);

            //retrieve the layout associated with our custom content type
            PageLayout[] layouts = webpublish.GetAvailablePageLayouts(new SPContentTypeId(MyContentTypeID));

            //first layout considered, as this is the one created by this feature
            PageLayout MyPageLayout = layouts[0];

            PublishingPageCollection PublishingPages = webpublish.GetPublishingPages();

            PublishingPage newPage = PublishingPages.Add("NewPublishingPageName.aspx", MyPageLayout);
            newPage.Title = "My first publishing page";

            newPage.ListItem.Update();

            //check-in and republish the page
            SPFile listItemFile = newPage.ListItem.File;

            //check that the file is not checked out - if it is,  check it in.
            if (listItemFile.CheckOutStatus != SPFile.SPCheckOutStatus.None)
            {
                listItemFile.CheckIn("Initial default content added.");
            }

            listItemFile.Publish("");
            listItemFile.Approve("");                
    }

答案 1 :(得分:1)

答案 2 :(得分:0)

我有类似的问题。事实证明,我必须发布上传的文件才能使其可见。

答案 3 :(得分:0)

我有与Tudor类似的解决方案,我会发布该代码以防万一:

...获取SiteCollection(SPSite)......

PublishingSite pSite = new PublishingSite(site);
PageLayout layout = pSite.PageLayouts["MyLayout"];

PublishingWeb pWeb = PublishingWeb.GetPublishingWeb(site);

if(pWeb.GetPublishingPages()[pWeb.PagesList.Title + "/" + "MyPage.aspx"] == null)
{
  PublishingPage page = pWeb.GetPublishingPages().Add("MyPage.aspx", layout);
  page.Title = "MyTitle";
  page.Update();
  page.CheckIn("Added MyPage.aspx");
}