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

发布于 2024-07-13 10:25:26 字数 338 浏览 9 评论 0原文

我正在尝试创建一个功能来在“页面”库中上传新的发布页面,但它无法按照我想要的方式工作。 如果我使用 SharePoint Designer 看到该库,则会出现我的发布页面,但如果我使用 Internet Explorer,则不会出现。

在该功能中,我配置属性:ContentTypeId、ContentTye、Author、Title、FileRef、FileDirRef、FileLeafRef、FileType、LinkFilenameNoMenu、LinkFilename 和 DocIcon。 在之前的功能中,我遇到了同样的问题,并通过放置 ContentTypeId 属性来解决。 在这种情况下,我不知道错误到底在哪里。

I'm trying to make a feature to upload a new publishing page in "Pages" library but it doesn't works the way I want. If I see the library using SharePoint Designer my publishing page appears, but it doesn't if I use Internet Explorer.

In the feature I configure the properties: ContentTypeId, ContentTye, Author, Title, FileRef, FileDirRef, FileLeafRef, FileType, LinkFilenameNoMenu, LinkFilename and DocIcon. In previous features, I faced the same problem and it was solved putting the ContentTypeId property. In this case, I don't know exactly where is the error.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

烛影斜 2024-07-20 10:25:26

我使用以下代码根据页面布局创建发布页面,该页面布局被认为已配置并基于内容类型。 该代码在您的功能的 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("");                
    }

I use the following code to create a publishing page based on a page layout which is considered to be already provisioned and based on a content type. The code runs in the FeatureActivated event handler for your feature:

    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("");                
    }
ㄖ落Θ余辉 2024-07-20 10:25:26

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

I had a similar problem. It turned out i had to publish the uploaded file to make it visible.

自我难过 2024-07-20 10:25:26

我有与 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");
}

I have similar solution as Tudor, I´ll publish that code to just in case:

...get 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");
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文