发布网站页面的对象模型操作
2008-02-15 11:41
369 查看
发布网站页面的对象模型操作
使用对象模型创建发布网站的页面并向其中填写文章页的内容。用代码的好处就是可以批量操作。
使用对象模型创建发布网站的页面并向其中填写文章页的内容。用代码的好处就是可以批量操作。
using System; using System.Collections.Generic; using System.Text; using Microsoft.SharePoint; using Microsoft.SharePoint.Publishing; using System.IO; namespace CreatePublishPage { class Program { public static void CreateNewPage(SPWeb web) { // TODO: Replace these variable values with your own // values. // // The URL name of the new page string newPageName = "testpage"; // // The comment to set when the page is checked in. string checkInComment = "Your check in comments"; // Validate the input parameters. if (null == web) { throw new System.ArgumentNullException("web"); } // Get the PublishingWeb wrapper for the SPWeb // that was passed in. PublishingWeb publishingWeb = null; if (PublishingWeb.IsPublishingWeb(web)) { publishingWeb = PublishingWeb.GetPublishingWeb(web); } else { throw new System.ArgumentException("The SPWeb must be a PublishingWeb", "web"); } // Create the new page in the PublishingWeb. PublishingPageCollection pages = publishingWeb.GetPublishingPages(); PageLayout[] plc = publishingWeb.GetAvailablePageLayouts(); PageLayout pageLayout = plc[0]; PublishingPage newPage = pages.Add(newPageName+".aspx", pageLayout); newPage.Title = newPageName; newPage.Update(); // Check the new page in so that other contributors // can work on it. byte[] fs = newPage.ListItem.File.OpenBinary(); string s = Encoding.UTF8.GetString(fs); //Edit the page content string news = "publishing page content. "; string ss = s.Replace(@"</mso:PublishingPageLayout>", "</mso:PublishingPageLayout><mso:PublishingPageContent msdt:dt=\"string\">"+news+"</mso:PublishingPageContent><mso:PublishingRollupImage msdt:dt=\"string\"></mso:PublishingRollupImage>"); byte[] ffs = Encoding.UTF8.GetBytes(ss); newPage.ListItem.File.SaveBinary(ffs); newPage.ListItem.File.Update(); // newPage.ListItem.File. newPage.CheckIn(checkInComment); publishingWeb.Update(); Console.WriteLine("Success!"); } static void Main(string[] args) { // CreateNewPage(); string url = "http://moss:8017/Pages"; SPSite site = new SPSite(url); SPWeb web = site.OpenWeb(); CreateNewPage(web); } } } |
相关文章推荐
- 发布网站页面的对象模型操作
- SharePoint 2013 对象模型操作"网站设置"菜单
- SharePoint 使用对象模型操作页面上的Web Part
- SharePoint 2013 对象模型操作"网站设置"菜单
- Sharepoint学习笔记—ECMAScript对象模型系列-- 4、使用ECMA操作网站对象(website)
- SharePoint【ECMAScript对象模型系列】-- 04. 使用ECMA操作网站对象(website)
- ASP.NET 页面对象模型
- C#操作Word (1)Word对象模型
- 【QTP】页面滚动条WinScrollBar对象操作(滚动条操作)
- SharePoint 2010开发实例精选——通过客户端对象模型删除页面上的Web部件
- C++对象模型之 Copy Constructor的建构操作
- sharepoint2010:使用服务端对象模型(Server-Side Object Model)操作列表
- SharePoint【ECMAScript对象模型系列】-- 05. 使用ECMA操作列表对象(list)
- ASP.NET 页面对象模型
- ASP.NET 页面对象模型
- SharePoint2010 SharePoint Fundation 服务器端对象模型之 枚举网站和网站集
- asp.net——网站发布后xml文件拒绝写入操作
- eclipse操作---改变编码方式(不同页面,project,某个文件,服务器发布目录)
- C++对象模型-复制构造函数的构造操作
- [.net 面向对象程序设计深入](6).NET MVC 6 —— 模型、视图、控制器、路由等的基本操作