How to use code to create a release page

Source: Internet
Author: User
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 = 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); newfolde R. 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. getpublishingweb (Web); pagelayout [] layouts = publishingweb. getavailablepagelayouts (); pagelayout layout = layouts [0]; string pagename = "mypublishingpage5.aspx"; Publ Ishingpage 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 t His page. Click 'edit page' to edit the page. "pagefile. Checkout (); response. Redirect (newpageurl + "? ControlMode = edit & displaymode = design ");}}});

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.