2008-09-04 37 views
2

Scenerio:SharePoint中的文檔庫,列x爲「Person或Group」類型。從VBA宏(或VSTO加載項)中,我們試圖訪問文檔上的MetaProperty來設置/獲取用戶名。任何嘗試通過ContentTypeProperties集合訪問值都會引發Type MisMatch錯誤(13)。如何使用VBA或VSTO從存儲在SharePoint中的Word文檔讀取/寫入人員元數據?

MetaProperty對象的Type屬性表示它是「msoMetaPropertyTypeUser」。我找不到如何使用這種類型的MetaProperties的例子。有人對此有經驗嗎?

謝謝!

回答

1

你應該能夠只是做這樣的事:

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的列名。

+0

爲了能夠定義SPSite類型的變量,我在哪裏可以找到我需要首先引用的dll? – ChadD 2009-05-30 18:20:59

1

我做到了。

這裏的訣竅實際上是知道如果您在Word文檔的自定義屬性中的MOSS用戶中放置了與用戶索引對應的字符串,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; 
相關問題