views:

2012

answers:

5

Scenerio: Document library in SharePoint with column x of "Person or Group" type. From within a VBA macro (or VSTO add-in) we're trying to access the MetaProperty on the document to set/get the user name. Any attempt to access the value via the ContentTypeProperties collection throws a Type MisMatch error (13).

The Type property of the MetaProperty object says it's "msoMetaPropertyTypeUser". I cannot find any examples of how to work with MetaProperties of this type. Anyone have any experience with this?

Thanks!

+1  A: 

You should be able to just do something like this:

    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";
            }
        }
    }

Any metadata for a document should be available by indexing the column name of the SPListItem.

Jason Z
In order to be able to define a variable of type SPSite, where do I find the dll that I need to reference first?
Velika
Microsoft.SharePoint.dll. It should be in the GAC on a machine with SharePoint installed. I have also found a copy of it in the C:\Program Files\Common Files\microsoft shared\Web Server Extensions\12\ISAPI folder.
Jason Z
+1  A: 

@Jason Z: Sorry, I should have been clearer. We're doing some automation within the word doc (filling out form fields) and there are several list columns in SharePoint that are required before we can check in the doc. So, we were trying to use the Office APIs to set the metadata, since the SharePoint API is not available on the client. If you look at the Word/Office API, you'll see that the Document object has a ContentTypeProperties collection that you're supposed to be able to use to set metadata properties. It works fine for text fields, but we don't know how to set a property that is a "User" type.

Your answer reminds me that we do have the SharePoint web services available on the client, so maybe we can find a workaround that way if the ContentTypeProperties collection cannot be used...

Thanks...

Jim Harte
+1  A: 

I would love a follow up on this because I do have the exact same problem Using both Office 2007 and MOSS 2007. I use VSTO Add-In to send a document to sharepoint using the direct mapping between Office.Document.CustomProperties and the field of a ContentType inside MOSS. since Office.MsoDocProperties enum doesn't have a "person or group" value, I tried other things, like put there a string with the full login or any identifier MOSS could easily recognize. There was a solution using an event handler inside MOSS to fill the column from an other string typed column with a user identifier, it's being looked at. I don't really see how you could use Web Services to make that work, I'd like to have information on how you finally resolved your problem.

Thanks in advance.

Paciv
+1  A: 

I did it.

The trick here is actually to know that if you put a string corresponding to the user index in MOSS users in the custom property of the Word document, MOSS will recognize it and find the corresponding user to map the field.

so you just need to call http:///_vti_bin/usergroup.asmx use the function GetUserInfo and retrieve the user index (ID) from it.

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;
Paciv
A: 

Paciv, Thank you for sharing your solution. Can you please elaborate? Are you still using a VSTO add-in? Thank you

Ron