This project has moved. For the latest updates, please go here.

Change and create documentProperties

Aug 6, 2013 at 10:18 AM
Hi there,
I try to build a solution in C# that change and create BuiltInDocumentProperties and CustomDocumentProperties of Word Documents (doc and docx). I test with NetOffice but my changes will not save in the Document. Can anybody help to solve my problem?

I test it like this:
try
{
  app = new Word.Application();
  Word.Document doc = app.Documents.Open(@"test.doc");
               
  ((NetOffice.OfficeApi.DocumentProperties)doc.CustomDocumentProperties)["Test"].Value = DateTime.Now.ToLongTimeString();
  ((NetOffice.OfficeApi.DocumentProperties)doc.CustomDocumentProperties).Add("NewProp", false, NetOffice.OfficeApi.Enums.MsoDocProperties.msoPropertyTypeString, DateTime.Now.ToLongTimeString());

  doc.Save();
catch { }
finally
{
  app.Quit();
  app.Dispose();
}
Coordinator
Aug 6, 2013 at 2:26 PM
this post facing the same problem

http://stackoverflow.com/questions/1527204/saving-word-2007-document-properties-in-c-sharp-2-0

"
When you add/change custom properties seems that the document is no changed,
so the WordApplication.ActiveDocument.Saved is still true.
Set it to false and then call the Save method of the Document, it will work!!
"

Sebastian
Aug 7, 2013 at 12:58 PM
Thx a lot, that solve this problem.
This works for local and network files, now I try to save files from Sharepoint (WSS 3.0 o_O) that didn´t works cause of other reasons. Does anybody know spontaneous a simple solution for the Sharepoint problem?
I start a google search by the way :)