![](/img/trans.png)
[英]Using VBA to read the metadata or file properties of files in a SharePoint doc library
[英]Read/write Person metadata from a Word doc stored in SharePoint using VBA or VSTO?
方案:SharePoint 中的文檔庫,列 x 為“個人或組”類型。 在 VBA 宏(或 VSTO 加載項)中,我們嘗試訪問文檔上的 MetaProperty 以設置/獲取用戶名。 任何通過 ContentTypeProperties 集合訪問該值的嘗試都會拋出一個
類型不匹配錯誤 (13)。
MetaProperty 對象的 Type 屬性表示它是msoMetaPropertyTypeUser
。 我找不到任何關於如何使用這種類型的 MetaProperties 的示例。 有人對此有經驗嗎?
謝謝!
我做到了。
這里的訣竅其實就是要知道,如果在Word文檔的自定義屬性中放入MOSS users 中用戶索引對應的字符串,MOSS 會識別並找到對應的用戶來映射字段。
所以你只需要調用 http:///_vti_bin/usergroup.asmx 使用函數 GetUserInfo 並從中檢索用戶索引(ID)。
MOSSusergroup.UserGroup userGroupService = new MOSSusergroup.UserGroup();
userGroupService.Credentials = System.Net.CredentialCache.DefaultCredentials;
System.Xml.XmlNode node = userGroupService.GetUserInfo(userLogin);
string index = node.FirstChild.Attributes["ID"].Value;
你應該能夠做這樣的事情:
using (SPSite site = new SPSite("http://yoursite/subsite"))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists["DocLibraryName"];
SPListItemCollection items = list.GetItems(list.Views["All Documents"]);
foreach (SPListItem item in items)
{
item["Modified By"] = "Updated Value";
}
}
}
應該可以通過索引 SPListItem 的列名來獲取文檔的任何元數據。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.