Adding a Guid as a CustomDocumentProperty


I have the following code in a project:

public byte[] GenerateMergedDocument(object[] fieldValues, Guid id)


doc.MailMerge.Execute(GetMergeFields(), fieldValues);

doc.CustomDocumentProperties.Add(“Id”, id);

MemoryStream dstStream = new MemoryStream();

doc.Save(dstStream, SaveFormat.FormatDocument);



The doc save method throws an exception:

[Exception: Do not know how to write a property value of this type.]

Any ideas?

I am essentially creating a merge document, but I want to uniquly identify each one (thus adding the GUID). Is this a hole in the code - or should I be implementing this differently?


Convert the guid to string before adding as a property. Only string, int, bool, double and DateTime property types are allows in MS Word documents. The fact it throws it on save is a good point, I will need to make sure it throws when you try to add the property with a type that's not allowed.

doc.CustomDocumentProperties.Add("Id", id.ToString());


Damn you guys are quick!

I just tried converting the guid to a string before I read your post and sure enough - works like a charm!

I do agree - you should throw the exception at the time of of the error
(i.e. when adding the property). Also - your documentation just says
that it takes an object - which I guess is nebulous since there are
some limitations. You may want to be clearer on that point.

Thanks again - you guys rock.

PS: any ideas on when pagination is built in?