I'm trying to write a C# application that iterates through a collection of Microsoft Office documents and standardizes the meta data of those documents (e.g. the author and company name). Unfortunately, I can't seem to figure out what libraries/classes I should use to do this, if they exist at all.
I have looked at the Microsoft.Office.Core namespace, but it seems that namespace only gives you a bunch of interfaces and no actual classes.
Is there a standard way to change the meta data of Microsoft Office Documents? If so, could anyone explain it to me?
If not, and there are different methods for each type of Office document, then I think I can assume for my project that I'll only be dealing with Word, Excel, and PowerPoint documents. If I made that assumption, how would I edit the meta data of each of those three kinds of documents?
Also, is there a way to test whether a file is an Office document (or specifically, a Word, Excel, or PowerPoint document) without just looking at the file extension and trusting it to be correct?
4 23144
I've figured out a solution. It's funny, I only found one helpful source on the web and the solution they gave didn't quite work. Below I've written methods that set and get Word, Excel, and PowerPoint file properties. - object GetWordDocumentPropertyValue(Word.Document document, string propertyName)
-
{
-
object builtInProperties = document.BuiltInDocumentProperties;
-
Type builtInPropertiesType = builtInProperties.GetType();
-
object property = builtInPropertiesType.InvokeMember("Item", BindingFlags.GetProperty, null, builtInProperties, new object[] { propertyName });
-
Type propertyType = property.GetType();
-
object propertyValue = propertyType.InvokeMember("Value", BindingFlags.GetProperty, null, property, new object[] { });
-
return propertyValue;
-
}
-
-
object GetExcelWorkbookPropertyValue(Excel.Workbook workbook, string propertyName)
-
{
-
object builtInProperties = workbook.BuiltinDocumentProperties;
-
Type builtInPropertiesType = builtInProperties.GetType();
-
object property = builtInPropertiesType.InvokeMember("Item", BindingFlags.GetProperty, null, builtInProperties, new object[] { propertyName });
-
Type propertyType = property.GetType();
-
object propertyValue = propertyType.InvokeMember("Value", BindingFlags.GetProperty, null, property, new object[] { });
-
return propertyValue;
-
}
-
-
object GetPowerPointPresentationPropertyValue(PowerPoint.Presentation presentation, string propertyName)
-
{
-
object builtInProperties = presentation.BuiltInDocumentProperties;
-
Type builtInPropertiesType = builtInProperties.GetType();
-
object property = builtInPropertiesType.InvokeMember("Item", BindingFlags.GetProperty, null, builtInProperties, new object[] { propertyName });
-
Type propertyType = property.GetType();
-
object propertyValue = propertyType.InvokeMember("Value", BindingFlags.GetProperty, null, property, new object[] { });
-
return propertyValue;
-
}
-
-
void SetWordDocumentPropertyValue(Word.Document document, string propertyName, string propertyValue)
-
{
-
object builtInProperties = document.BuiltInDocumentProperties;
-
Type builtInPropertiesType = builtInProperties.GetType();
-
object property = builtInPropertiesType.InvokeMember("Item", System.Reflection.BindingFlags.GetProperty, null, builtInProperties, new object[] { propertyName });
-
Type propertyType = property.GetType();
-
propertyType.InvokeMember("Value", BindingFlags.SetProperty, null, property, new object[] { propertyValue });
-
document.UpdateSummaryProperties();
-
document.Save();
-
}
-
-
void SetExcelWorkbookPropertyValue(Excel.Workbook workbook, string propertyName, string propertyValue)
-
{
-
object builtInProperties = workbook.BuiltinDocumentProperties;
-
Type builtInPropertiesType = builtInProperties.GetType();
-
object property = builtInPropertiesType.InvokeMember("Item", System.Reflection.BindingFlags.GetProperty, null, builtInProperties, new object[] { propertyName });
-
Type propertyType = property.GetType();
-
propertyType.InvokeMember("Value", BindingFlags.SetProperty, null, property, new object[] { propertyValue });
-
workbook.Save();
-
}
-
-
void SetPowerPointPresentationPropertyValue(PowerPoint.Presentation presentation, string propertyName, string propertyValue)
-
{
-
object builtInProperties = presentation.BuiltInDocumentProperties;
-
Type builtInPropertiesType = builtInProperties.GetType();
-
object property = builtInPropertiesType.InvokeMember("Item", System.Reflection.BindingFlags.GetProperty, null, builtInProperties, new object[] { propertyName });
-
Type propertyType = property.GetType();
-
propertyType.InvokeMember("Value", BindingFlags.SetProperty, null, property, new object[] { propertyValue });
-
presentation.Save();
-
}
This codes works with already-opened Word, Excel, and PowerPoint files, and opening them is another issue altogether, but a small amount of Googling will help you find the answer pretty quickly.
It should be noted that if you want to update the field that appears in Word 2007 as 'status' use the name 'Content Status' to access it.
Great post!
i want program in c# types of inheritance with get and set method and base consttructor should be called and use access specifier
u save my life bro. thank you so much..
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Pugi! |
last post by:
Hi,
I would like to upload office-document (doc, xls, ...) using a form to a
website (apache, php, mysql) in a specific directory and if possible insert
it into a table (MySQL-db). Is this...
|
by: Shakil Khan |
last post by:
Hi there ...
My question is about Meta Data which is automatically saved with some files.
For example,when an MS Office Documents is saved, it automaticaly save some
extra information with the...
|
by: Stedak |
last post by:
My application seems to freeze when Microsoft Office Document Imaging is set
as the default for loading images. If the Windows Picture and Fax Viewer is
used there is no problem. When I set a break...
|
by: VM |
last post by:
Is it possible to view an Office document in a web form? I'm looking for a
control that will allow me to show a Word doc or PDF dynamically.in my web
form.
It's like an document embedded into the...
|
by: tubby |
last post by:
Silly question, but here goes... what's a good way to determine when a
file is an Open Office document? I could look at the file extension, but
it seems there would be a better way. VI shows this...
|
by: boarderstu |
last post by:
Hi All,
I'm looking for some tuts or advice on reading Meta data from files -
preferably Exif data, any body got any advice on this?
ta
|
by: Dylan |
last post by:
Hello,
I was trying to do a WCF tutorial (http://wcf.netfx3.com/content/
BuildingHelloWorld.aspx). I need to get the meta data from my service
usin svcutil.exe why is not working? Please see...
|
by: samurai jack |
last post by:
Hi all champs
I am trying to print one doc using Microsoft office document Image writer. But it opens the document ( *.prn file ) after spooling and before sending it to print. And does not give...
|
by: palamadai |
last post by:
hii ppl, I would like to create a password protected open office document and write some data to the document.After writing I would like to read the same document in C#.net 3.5 windows app.I would...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |