这正是我们在项目中所做的:)你很幸运。
首先,您需要为该文档库创建事件接收器。并且您需要实现 ItemUpdated 和 ItemAdded。请参阅
http://www.dotnetcurry.com/ShowArticle.aspx?ID=649
http://blogs.msdn.com/b/brianwilson/archive/2007/03/05/part-1-event-handlers-everything-你需要知道的关于微软办公室共享点门户服务器苔藓事件处理程序.aspx
//事件接收器的代码。这将为您提供内容控件的名称及其值
Dictionary<string, string> results = new Dictionary<string, string>();
using (Stream stream = file.OpenBinaryStream(SPOpenBinaryOptions.SkipVirusScan)) {
using (WordprocessingDocument doc = WordprocessingDocument.Open(stream, true)) {
var contentControls = doc.MainDocumentPart
.GetXDocument()
.Descendants(w + "sdt");
foreach ( var contentControl in contentControls )
{
string key = (string)contentControl.Descendants(w + "sdtPr").Elements(w + "alias").Attributes(w + "val").FirstOrDefault();
string val = GetTextFromContentControl(contentControl);
results[key] = val;
}
}
static string GetTextFromContentControl(XElement contentControlNode) {
return contentControlNode.Descendants(w + "p")
.Select
(
p => p.Elements()
.Where(z => z.Name == r || z.Name == ins || z.Name == br)
.Descendants()
.Where(z => z.Name == w + "t" || z.Name == w + "br")
.StringConcatenate(element => (string)element + (element.Name == w + "br" ? Environment.NewLine : "")) + Environment.NewLine
).StringConcatenate();
}