Showing posts with label Microsoft Word 2007. Show all posts
Showing posts with label Microsoft Word 2007. Show all posts

Dec 15, 2011

Creating Custom Properties in Word 2007

In the previous article, I have explained about creating custom properties in word 2003. In this article, we will see how to create custom properties in word 2007.
It is slightly different from word 2003 and involves the following steps.
1. Open the Microsoft Word 2007 and create a new word document.
2. For creating the Bookmark, we need Developer Tools option in the Microsoft Word Menu.
3. Hence, lets enable it by following the steps below
     a) Click the Microsoft Office button -> word options-> popular tab-> In the “top options for
         working with word” -> select the check box named “show Developer tab in the Ribbon”
     b) You will a see the tab like shown below
                       


4.Now we will create the bookmark.
5. Select Developer Tab option-> select the legacy control as shown below
6. Here we are going to use only text boxes which is shown in the controls as “ab” as shown above in the red mark.
7. Now, Insert the text box control (a gray shaded portion will be inserted)
8. Now click on the text box inserted or properties in the developer tab to set the properties. You will see the properties window (Text Form Field Options) will pop up as shown below.


9. You have many options in that. But we are using only Bookmark option here. We will give the bookmark name as “CompanyName” as shown below.
10. Now we have to assign and link this property by giving a name to it.
11. Click Microsoft Office Button -> Prepare ->Properties  you will see as below.
12. Click on the Advanced properties you will see the pop up window as shown below
13. Click on the custom tab and give a name to the field you are going to create
(here used  ComapanyName ) in the Name field.

14. Then click link to the content in the source. You will see a list of source available. So here we will see the “Company Name” created as shown below.
15. Clicking ADD you will see the custom properties being created in the properties as below
16. That’s it. We have created a bookmark and set it as a Custom Property in the word.

17. If the user enters a value in the bookmark, then the value will be set to the created property as shown below.



Thats it. Enjoy!

Creating Custom properties in Word 2003

In the articles Part I,Part II and Part III we have discussed about how to read the custom properties of word 2003 using  DSO dll in C# .Net.
In this article we are going to see about creating a bookmark and set the custom properties for the Microsoft Word 2003.
Steps
1. Open the Microsoft Word 2007 and create a new word document.
2. For creating the Bookmark, we need Forms option in the Microsoft Word Menu.
3.  Right click on the Menu bar and you will see forms options and check the option you will see the forms menu
4.   Then click the Textbox option (will be having a symbol ”ab”)

5.  Insert a text box and mouse click to see the properties.
6.   Now in the Bookmark option give the property name (here I gave it as CompanyName )

7. Now go to File Menu->properties-> Custom properties tab as shown below

8.  Now in the Name field give the Name (I gave as TestCompany) and check the Link to Content so that you will see the bookmark created and link the content we have created (CompanyName)
9. Now you will see the added property as below.

10. Click Add and now the properties are set. If you type a value in the document, the value must be assigned and you can see in the properties as shown below.
So, once the properties are set we can read the values using c# .Net.
Enjoy! 




Dec 11, 2011

Reading Custom Properties of Word Document

Part III
Read the Introduction about this article Part I
Read about reading the summary properties of word document in this article Part II
In this post, we can see what is the code for the reading the custom properties of the word document.
public static void GetDocumentCustomProperties(string filename)
{
            OleDocumentPropertiesClass doc = new OleDocumentPropertiesClass();
            doc.Open(filename, true, dsoFileOpenOptions.dsoOptionOpenReadOnlyIfNoWriteAccess);
            //Reading and writing the custom properties to a file
            StreamWriter sw1= new StreamWriter(@"D:\FileRead_Custom.txt");
            CustomProperties obj_CustomProp = doc.CustomProperties;
            foreach (CustomProperty custom_prop in obj_CustomProp )
            {
                sw1.WriteLine(custom_prop.Name   "    "   custom_prop.get_Value());
            }
            sw1.Close();
            doc.Close(false);
}
Hope this helps you!

Reading Summary Properties of Word Document

Part II
Read the Introduction about this article Part I
In this post, we can see what is the code for the reading the summary properties of the word document.
public static void GetDocumentSummaryProperties(string filename)
{
            DSOFile.OleDocumentPropertiesClass doc = new DSOFile.
            OleDocumentPropertiesClass();
            doc.Open(filename, false,

            DSOFile.dsoFileOpenOptions.dsoOptionOpenReadOnlyIfNoWriteAccess );

            //getting the properties of the document
            DSOFile.SummaryProperties summaryProp = doc.SummaryProperties;

            //reading and writng the summary properties to a file
            string author = summaryProp.Author;
            string comapanyName = summaryProp.Company;
            string managerName = summaryProp.Manager;
            StreamWriter sw = new StreamWriter(@"D:\FileRead.txt");
            sw.WriteLine(author);
            sw.WriteLine(comapanyName);
            sw.WriteLine(managerName);
            sw.Close();
}
That’s It. Enjoy Happy Coding!
Also, read how to Read the Custom Properties of Word Document Part III

Reading Document Properties

Part I
We are going to discuss about a interesting topic which can be used in SharePoint and also in .Net.
It is possible to reading the summary properties and custom properties of the word document and it is also one of the requirements now a days.
This can be done through using DSO dll which can be downloaded from the below link
(Important Note: This is a 32 bit dll )

What is DSO dll ?
The Dsofile.dll sample file is an in-process ActiveX component for programmers that use Microsoft Visual Basic .NET or the Microsoft .NET Framework. You can use this in your custom applications to read and to edit the OLE document properties that are associated with Microsoft Office files, such as the following: 
• Microsoft Excel workbooks
• Microsoft PowerPoint presentations
• Microsoft Word documents
• Microsoft Project projects
• Microsoft Visio drawings
• Other files that are saved in the OLE Structured Storage format
The Dsofile.dll sample file is written in Microsoft Visual C++. The Dsofile.dll sample file demonstrates how to use the OLE32 IPropertyStorage interface to access the extended properties of OLE structured storage files.
Features of this DLL
1. This dll is 32 bit and can read only Microsoft word 2003 (ie., .doc) formats only.
2. It has a OLE property reader class which can read the properties of the word document.
3. Using this dll, we can read both the Summary properties and also the Custom properties we create for the documents.
4. Also with this dll, we can set the custom properties programmatically.

Also, Read how to extract the summary properties of the word document in this article Part II.