Storing custom metadata in a Word 2010 document(Interop)
-
13. března 2012 7:26
Good Morning
I would like to know if there is a way to store a custom object inside a Word 2010 document and if you could please point me to any helpful resources on how this can be done?
Basically while the document is open in Word I create a new instance of my Metadata class shown below and populate it with custom data,when the document is saved on the local machine I want to somehow embed this object in the Word document so next time it's open i have access to the properties defined in the class below:
I'm using C# .NET 4.0 and Word 2010 vsto
public class Metadata { public string TemplateName { get; set; } public string TemplateDescription { get; set; } public List<string> Languages { get; set; } public List<string> Categories { get; set; } public List<string> Types { get; set; } }
Všechny reakce
-
13. března 2012 9:19
Hi Denys,
You can use the Documents Variables property. I don't think you can store entire .net objects innside. But you can create a custom variable for each of your metadata properties.
EXAMPLE
To create a variable on a Word document:
wordDocument.Variables.Add("TemplateName", Metadata.TemplateName.ToString());
To retreive the value at a later time:
Variable templateNameVariable = wordDocument.Variables["TemplateName"];
Give it a try :)
string templateName = templateNameVariable.ToString();
- Označen jako odpověď Tom_Xu_WXModerator 16. března 2012 7:20
-
13. března 2012 10:01or you can use JSON or XML serialization.
-
14. března 2012 4:55
Thanks, used serialization and custom properties
private void AddCustomProperty(string name, string value, Office.MsoDocProperties type) { object missing = System.Reflection.Missing.Value; Office.DocumentProperties props = (Office.DocumentProperties)CurrentDocument.CustomDocumentProperties; props.Add(name, false, type, value, missing); }
- Označen jako odpověď Tom_Xu_WXModerator 16. března 2012 7:20
-
14. března 2012 8:42just remember that user will see it in document panel.