Excellent work, and you are almost there! The trick from there is to cast the "Item" property of the field (when you know it is a Keyword) to a DocumentIndexFieldKeywords type (which is built into the DocuWare .NET platform libs). Here is a foreach loop that extends your code to get just such an object (I bold-faced the line I added):
foreach (Document doc in docs.Items)
Document document = doc.GetDocumentFromSelfRelation();
foreach (DocumentIndexField field in document.Fields)
if (field.ItemElementName.ToString() == "Keywords")
DocumentIndexFieldKeywords keywords = (DocumentIndexFieldKeywords)field.Item;
The "keywords" variable (that is of type DocumentIndexFieldKeywords) has a property called "Keyword" that is a standard List<string>. So, you can get the count of the keywords via:
and would access the first string in the List via something like:
string firstKeyword = keywords.Keyword;
That should get you where you need to be.
It is very weird that you have to instantiate a second Document object via GetDocumentFromSelfRelation() when the items in the query result are already of type Document. Not sure if that is a bug or what. But I guess when in doubt, re-pull the document from its self-relation and get everything back that you need. From there, it is just a matter of casting the right property to the right type so it can be accessed without the compiler getting cranky or a run-time error being thrown.Just FYI, but if you try the above cast on a field that is not of the Keyword type, a run-time cast exception is thrown.
Thanks for working through this! Great info!