公司内部有很多部门都创建了Wiki库,来做知识共享。公司是Hosting的SharePoint环境,不能写服务器端代码,要操作Wiki只能通过Web Service来完成,所以,碰到两个情况:

1)Wiki库中已经有了几百篇的文章,文章中有些文字需要更新,几百篇文章手动更新肯定累死;

2)有人想写个程序,自动将包含图片的Word文档内容新建成Wiki;

说白了,其实就是如何使用SharePoint Web Service来新建和更新Wiki页面。

在SharePoint里面,Wiki虽然也可以看成是List,但是又有些特殊,每篇Wiki就是一个aspx页面,Wiki的内容则存储在Wiki条目的WikiField字段里面。

1)对于更新Wiki页面的内容,我们可以使用Lists.asmx的UpdateListItems来完成:

以下是一个批量替换Wiki内容中的一段文字的代码示例:

Lists.Lists SPLists = new Lists.Lists();
SPLists.Credentials = System.Net.CredentialCache.DefaultCredentials;
SPLists.Url = strListsSvrURL; //拼更新列表字段的XML
XmlDocument doc = new XmlDocument();
XmlElement batch = doc.CreateElement("Batch");
batch.SetAttribute("OnError", "Continue");
batch.SetAttribute("ListVersion", "1"); //获取Wiki库的所有Wiki条目
XmlNode ListItems = SPLists.GetListItems(strWikiLibName, null, null, null, null, null, null); foreach (XmlNode ListItem in ListItems.ChildNodes[1].ChildNodes)
{
if (ListItem.Attributes != null)
{
try
{
batch.InnerXml += "<Method ID='1' Cmd='Update'>" +
"<Field Name='ID'>" + ListItem.Attributes["ows_ID"].Value + "</Field>" +
"<Field Name='WikiField'><![CDATA[" + ListItem.Attributes["ows_WikiField"].Value.Replace(strOriginal, strNew) + "]]></Field>"
+ "</Method>";
}
catch { }
}
}
SPLists.UpdateListItems(strWikiLibName, batch);

 

 

2)对于新建Wiki页面,我们不能使用Lists.asmx的UpdateListItems,通过传递<Method ID='1' Cmd='New'>…命令来完成,一个办法是使用Copy.asmx,复制Wiki库中的一个Wiki页面,生成一个新的Wiki页面,更新它的WikiField字段。

string strWikiHomeURL = "http://site/wiki/home.aspx";

Copy.Copy SPListCopy = new Copy.Copy();
SPListCopy.Credentials = System.Net.CredentialCache.DefaultCredentials;
SPListCopy.Url = strCopySvrURL; Copy.FieldInformation[] HomePagefieldInformation;
byte[] HomePageContentBytes; uint myGetUint = SPListCopy.GetItem(
strWikiHomeURL,
out HomePagefieldInformation,
out HomePageContentBytes); //Wiki Page Title
string WikiName = "New" + DateTime.Now.ToString();
WikiName = WikiName.Replace("/", "").Replace(":", "").Replace(" ",""); Copy.FieldInformation headerInformation = new Copy.FieldInformation();
headerInformation.DisplayName = "Name";
headerInformation.InternalName = "LinkFilename";
headerInformation.Type = Copy.FieldType.Note;
headerInformation.Value = WikiName; Copy.FieldInformation contentType = new Copy.FieldInformation();
contentType.DisplayName = "ContentType";
contentType.InternalName = "ContentType";
contentType.Type = Copy.FieldType.Text;
contentType.Value = "Wiki Page"; Copy.FieldInformation wikiField = new Copy.FieldInformation();
wikiField.DisplayName = "Wiki Content";
wikiField.InternalName = "WikiField";
wikiField.Type = Copy.FieldType.Text;

引用自:http://blog.knowsky.com/177404.htm

最新文章

  1. struts2国际化
  2. [Penetration Testing Devil Training Camp Based on Metasploit] Learn &amp; Practice
  3. 远方的塔--Pylons
  4. ios initialize和init等方法
  5. Leetcode 345 Reverse Vowels of a String 字符串处理
  6. js首字母大写--单个单词的处理方式
  7. Java线程新特性--- Lock
  8. Java正则表达式(1)
  9. Apache配置完虚拟主机后,使用Chrome访问localhost还是默认目录htdocs
  10. 实现js浮点数加、减、乘、除的精确计算(网上很多文章里的方法是不能解决所有js浮点数计算误差的)
  11. if语句之猜拳
  12. 基于Java的开源CMS系统选择(转)
  13. PHP获取表单方法
  14. [转载] Redis实现分布式锁
  15. Linux环境下安装配置Node.js
  16. 归一化(softmax)、信息熵、交叉熵
  17. Eclipse + ndk+ cocos2dx 调试Cocos2dx 程序
  18. 题解——CodeForces 438D The Child and Sequence
  19. OpenSSH多路复用Multiplexing配置
  20. Java中取两位小数

热门文章

  1. [hadoop读书笔记] 第一章 初识 Hadoop
  2. Visual Studio的Debugger Visualizers
  3. 3D打印浪潮中的赢家与输家
  4. myeclipse重新添加spring支持
  5. (笔记)Mysql命令desc:获取数据表结构
  6. 第三百六十四节,Python分布式爬虫打造搜索引擎Scrapy精讲—elasticsearch(搜索引擎)的mapping映射管理
  7. Java如何获取正在运行的线程的Id?
  8. JDBC流ASCII和二进制数据
  9. Python操作SQLServer示例(转)
  10. eclipse中svn提交报错的解决