For anybody who wants it here you go.
try{
// Find an existing client instance that is logged in to the repository
IEnumerable<ClientInstance> clients = lfclient.GetAllClientInstances();
foreach (ClientInstance client in clients)
{
if (client.ProcessID == pid)
{
IEnumerable<ClientWindow> windows = client.GetAllClientWindows();
foreach (ClientWindow window in windows)
{
if (window.Hwnd == (IntPtr)hwnd)
{
if (window.GetWindowType() == ClientWindowType.DocumentViewer)
{
DocumentViewer docwindow = (DocumentViewer)window;
RepositoryConnection Res = docwindow.GetCurrentRepository(); //Get the document viewer's ClientAutomation.RepositoryConnection
Res.GetConnectionString(); //Call RepositoryConnection.GetConnectionString() to get the serialized connection
//create a RepositoryAccess.Session by calling Session.CreateFromSerializedLFConnectionString
Session MySession = Session.CreateFromSerializedLFConnection(Res.GetSerializedConnection());
DocumentInfo doc;
doc = Document.GetDocumentInfo(docwindow.GetDocumentId(), MySession);
FieldValueCollection fieldValues = doc.GetFieldValues();
//update the MetaData
fieldValues["Company Name"] = cbSupplierlist.Text.Substring(0, cbSupplierlist.Text.IndexOf("-") -1);
fieldValues["MFG VendorID"] = cbSupplierlist.Text.Substring(cbSupplierlist.Text.IndexOf("-") + 1);
doc.SetFieldValues(fieldValues);
doc.Save();
docwindow.Refresh();
Application.Exit();
}
}
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
}