Tuesday, November 17, 2009

Create a blank page in Pages Library

You need to perform these steps:

Get a blank page from file system or using the below function

StringBuilder sb = new StringBuilder();
sb.Append("<%@ Page Inherits=\"Microsoft.SharePoint.Publishing.TemplateRedirectionPage,Microsoft.SharePoint.Publishing,");
sb.Append("Version=12.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c\" %> <%@ Reference VirtualPath=\"~TemplatePageUrl\" ");
sb.Append("%> <%@ Reference VirtualPath=\"~masterurl/custom.master\" %><html xmlns:mso=\"urn:schemas-microsoft-com:office:office\" ");
sb.Append("xmlns:msdt=\"uuid:C2F41010-65B3-11d1-A29F-00AA00C14882\"><head>&nbsp;<!--[if gte mso 9]><xml>");
sb.Append("<mso:CustomDocumentProperties><mso:PublishingContact msdt:dt=\"string\">1218</mso:PublishingContact>");
sb.Append("<mso:display_urn_x003a_schemas-microsoft-com_x003a_office_x003a_office_x0023_PublishingContact ");
sb.Append("msdt:dt=\"string\">avanade</mso:display_urn_x003a_schemas-microsoft-com_x003a_office_x003a_office_x0023_PublishingContact>");
sb.Append("<mso:PublishingContactPicture msdt:dt=\"string\"></mso:PublishingContactPicture>");
sb.Append("<mso:PublishingContactName msdt:dt=\"string\"></mso:PublishingContactName>");
sb.Append("<mso:ContentTypeId msdt:dt=\"string\">0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF390064");
sb.Append("DEA0F50FC8C147B0B6EA0636C4A7D40073BD3FF4186E874380ADB2C06F742F8E</mso:ContentTypeId>");
sb.Append("<mso:Comments msdt:dt=\"string\"></mso:Comments>");
sb.Append("<mso:PublishingContactEmail msdt:dt=\"string\"></mso:PublishingContactEmail>");
sb.Append("<mso:PublishingPageLayout msdt:dt=\"string\">/_catalogs/masterpage/BlankWebPartPage.aspx, ");
sb.Append("Blank Web Part Page</mso:PublishingPageLayout>");
sb.Append("</mso:CustomDocumentProperties>");
sb.Append("</xml><![endif]--><title></title></head>");
Byte[] blankPage = ASCIIEncoding().GetBytes(sb.ToString());

 

Now, add this blank page to the Pages Library

SPList list = web.Lists["Pages"];

SPFile file= list.RootFolder.Files.Add(“blankpage.aspx”, blankPage);

0 comments: