Adding custom properties in docx file
Posted: Thu Jan 30, 2014 10:58 pm
Hello Everyone,
I need to add some custom properties in docx file.Can some one tell me how to doit
My flows goes something like below
Can someone tell me how add custom properties in docx file.Please see the how i have tried doing it.But it is adding the property in the docx advance property section which sharepoint is not able to retrive
and my customm.xml looks like the following
But the code above adds the abstract and citation in advance property dialog box which sharepoint in not able to retrive.
Can someone suggest me how to achieve it?
Thanks & Regards
Amarendra Thakur
I need to add some custom properties in docx file.Can some one tell me how to doit
My flows goes something like below
1 - export some content from webapp in a docx file
2 - add some custom meta data in this docx file
3 - upload this file sharepoint
4 - Sharepoint should be able to retrieve these metedata after uploading the file
Can someone tell me how add custom properties in docx file.Please see the how i have tried doing it.But it is adding the property in the docx advance property section which sharepoint is not able to retrive
- Code: Select all
WordprocessingMLPackage wordMLPackage =
WordprocessingMLPackage.load(new java.io.File(Input file path));
// Create a new Part
org.docx4j.openpackaging.parts.DocPropsCustomPart docPropsCustomPart
= new org.docx4j.openpackaging.parts.DocPropsCustomPart();
// Read the contents of the file into the part
java.io.InputStream is = new java.io.FileInputStream("custom.xml");
docPropsCustomPart.unmarshal(is);
docPropsCustomPart.setProperty("Abstract", "nanotechnology");
docPropsCustomPart.setProperty("Citation", "Medicine");
// Attach the part to the package
wordMLPackage.addTargetPart(docPropsCustomPart);
wordMLPackage.getMainDocumentPart().addParagraphOfText("Testing");
URI uri = new URI("/word/document.xml");
wordMLPackage.getContentTypeManager().addOverrideContentType(uri, "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml");
wordMLPackage.save(new java.io.File(output file path));
System.out.println("Docx created!!!");
and my customm.xml looks like the following
- Code: Select all
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/custom-properties" xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">
<!--<property fmtid="{D5CDD505-2E9C-101B-9397-08002B2CF9AE}" pid="2" name="ContentTypeId"><vt:lpwstr>0x01010034D2D07E1C911441AAB1B507BCEE86AD</vt:lpwstr></property>
<property fmtid="{D5CDD505-2E9C-101B-9397-08002B2CF9AE}" pid="3" name="_dlc_policyId"><vt:lpwstr>0x0101|2132935403</vt:lpwstr></property>
<property fmtid="{D5CDD505-2E9C-101B-9397-08002B2CF9AE}" pid="4" name="ItemRetentionFormula"><vt:lpwstr><formula id="xyz.Collab.Policies.GlobalPolicy" /></vt:lpwstr></property>
<property fmtid="{D5CDD505-2E9C-101B-9397-08002B2CF9AE}" pid="6" name="RCSExpiration"><vt:lpwstr>2;#3|7ec9b844-99bd-4405-bc7a-8f0c53bd09c7</vt:lpwstr></property>
<property fmtid="{D5CDD505-2E9C-101B-9397-08002B2CF9AE}" pid="7" name="TaxKeyword"><vt:lpwstr>20;#COP|06824ca1-e94f-419c-9416-0ddfd763ff32;#21;#CO|2fa3969e-d791-4b56-9e30-515ec76c57a0</vt:lpwstr></property>-->
<property fmtid="{D5CDD505-2E9C-101B-9397-08002B2CF9AE}" pid="7" name="Abstract"><vt:lpwstr></vt:lpwstr></property>
</Properties>
But the code above adds the abstract and citation in advance property dialog box which sharepoint in not able to retrive.
Can someone suggest me how to achieve it?
Thanks & Regards
Amarendra Thakur