Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem With Setting Word Properties in C#?
    primarykey
    data
    text
    <p>I wrote simple code to open a Word file (.docx) and set properties for that file. This code do exactly itself job. But when C# opens Microsoft Word I should update all fields to see real values which are updated from my code!</p> <p><strong>I want to know, what I do in my code to when Microsoft Word is open, all properties have real values and no more need to update properties with mysself?</strong> </p> <p>this is my code:</p> <p><strong>tip:dictionary properties contain property name and value.</strong> </p> <pre><code>public void SetWordFile(string FilePath, Dictionary&lt;string, object&gt; properties) { Microsoft.Office.Interop.Word._Application oWord = new Microsoft.Office.Interop.Word.Application(); Microsoft.Office.Interop.Word._Document oDoc; object originalFormat = Missing.Value; object routeDocument = Missing.Value; object oMissing = Missing.Value; object saveChanges = false; object oDocBuiltInProps; object oDocAuthorProp; Type typeDocAuthorProp; oWord.Visible = true; object oFalse = false; object filePath = FilePath; oDoc = oWord.Documents.Open(ref filePath, ref oMissing, ref oFalse, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); oDocBuiltInProps = oDoc.CustomDocumentProperties; Type typeDocBuiltInProps = oDocBuiltInProps.GetType(); foreach (string item in properties.Keys) { oDocAuthorProp = typeDocBuiltInProps.InvokeMember("Item", BindingFlags.Default | BindingFlags.GetProperty, null, oDocBuiltInProps, new object[] { item }); typeDocAuthorProp = oDocAuthorProp.GetType(); typeDocAuthorProp.InvokeMember("Item", BindingFlags.Default | BindingFlags.SetProperty, null, oDocBuiltInProps, new object[] { item, properties[item] }); Thread.Sleep(10); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload