zoukankan      html  css  js  c++  java
  • 如何用代码创建发布页

    static void Main(string[] args)
     
    {
     
    
    string newPageUrl = "";
     
    
    SPSecurity.RunWithElevatedPrivileges(delegate()// executing this code with elevated privileges will help whenever we create the publishing pages from a sharepoint portal site for an another portal site.If we create the publishing page within a site collection then this code will execute fine without elevated privileges.
     
    {
     
    
    using (SPSite site = new SPSite("http://sigr8-1b:45907/sites/sas")) // provide your portal site URL
     
    {
     
    
    using (SPWeb web = site.OpenWeb())
     
    {
     
    web.AllowUnsafeUpdates = 
    
    true;
     
    
    SPList list = web.Lists["Pages"];
     
    
    String url = list.RootFolder.ServerRelativeUrl.ToString();
     
    
    // create a new folder 
    
    
    string strFolderName = "Folder7" ;
     
    
    SPListItem newFolder = list.Items.Add(url, SPFileSystemObjectType.Folder, strFolderName);
     
    newFolder.Update();
     
    
    // if you want to add the new page in a existing folder you can take it by it's ID like below
     
    
    //SPListItem newFolder = list.Folders.GetItemById(3);
     
    
    // creating a publishing web
     
    
    PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web);
     
    
    PageLayout[] layouts = publishingWeb.GetAvailablePageLayouts();
     
    
    PageLayout layout = layouts[0];
     
    
    string pageName = "MyPublishingPage5.aspx";
     
     
     
    
    PublishingPage newPage = publishingWeb.GetPublishingPages().Add(newFolder.Folder.ServerRelativeUrl + "/"+ pageName, layout);
     
    
    // if you want to add the new page direclty inside the pages library then you can use the below line of code
     
    
    //PublishingPage newPage = publishingWeb.GetPublishingPages().Add(pageName, layout);
     
     
     
    
    // setting the URL value to the newPageUrl for redirecting the user after creating it
     
    newPageUrl = web.Url + 
    
    "/" + newPage.Url;
     
    newPage.Description = 
    
    "This my sample publishing page";
     
    newPage.Title = 
    
    "My Publishing Page";
     
    newPage.Update();
     
     
     
    
    //Now we can checkin the newly created page to the “pages” library
     
    
    SPFile pageFile = newPage.ListItem.File;
     
    
    if (pageFile.CheckOutStatus != SPFile.SPCheckOutStatus.None)
     
    {
     
    pageFile.CheckIn(
    
    "CheckedIn");
     
    pageFile.Publish(
    
    "publihsed"); 
    
    }
     
    
    // If you are executing this code in a web app then if you want to redirect the user to the newly created page with edit mode. Remember, we need to checkout the page before redireting the user to that page in edit mode, other wise you will get an Authoring error with message “You have not checked out this page. Click ‘Edit Page’ to edit the page.”
     
    pageFile.CheckOut();
     
    Response.Redirect(newPageUrl + 
    
    "?ControlMode=Edit&DisplayMode=Design");
     
    }
     
    }
     
    }); 
    

      

  • 相关阅读:
    各种基础网络的通道数及尺寸问题记录
    LPRnet轻量级实时车牌识别,主网络代码以及论文思路简要介绍
    python保存字符串到txt文件
    python删除目录下文件大小小于某个值的方法
    pyqt5注意事项
    github上传项目,更新项目
    python删除一个目录下某个类型的文件,以及删除目录下子目录的所有文件
    redis批量删除key
    mongodb常用操作
    curl参数为List<实体类>的请求方式
  • 原文地址:https://www.cnblogs.com/olay/p/3177360.html
Copyright © 2011-2022 走看看