1

我試圖使一個功能在「Pages」庫中上傳新的發佈頁面,但它不按我想要的方式工作。如果我看到使用SharePoint Designer的庫,則會顯示我的發佈頁面,但如果我使用Internet Explorer,則不會。如何使用功能上傳發布頁面?

在該功能中,我配置屬性:ContentTypeId,ContentTye,Author,Title,FileRef,FileDirRef,FileLeafRef,FileType,LinkFilenameNoMenu,LinkFilename和DocIcon。在以前的功能中,我面臨同樣的問題,並解決了ContentTypeId屬性。在這種情況下,我不清楚錯誤到底在哪裏。

回答

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("");     
    } 
0

我也有類似的解決方案,帝舵,I'll發佈代碼,以防萬一:

...得到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"); 
} 
相關問題