All,
I am trying to open a word document and get all the properties using .NET
(c#), if I create the wordapp, call the correct methods I get invalid cast
(see code examples), but if I create a WORD PROJECT (from C#) and use the
Application (thisApplication) the word project creates, it works fine, but
this is far from a acceptable work around as doing it this way means I have
to trigger the code from word.
This does not work (Watch for the word wrap):
void TestUsing_WORDAPP()
{
object missing = System.Reflection.Missing.Value;
object filename = @"C:\1.doc";
Word.ApplicationClass wordApp = new
Microsoft.Office.Interop.Word.ApplicationClass(); // I HAVE TRIED USING THE
INTERFACE HERE
Word.Document wordDoc = wordApp.Documents.Open(ref filename,ref
missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref
missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref
missing,ref missing,ref missing);
// Get the props
Microsoft.Office.Core.DocumentProperties docprops
=(Microsoft.Office.Core.DocumentProperties)
wordDoc.BuiltInDocumentProperties; // INVALID CAST HERE
System.Diagnostics.Trace.WriteLine(docprops.Count) ;
}
And this does work.
void TestUsing_This()
{
object missing = System.Reflection.Missing.Value;
object filename = @"C:\1.doc";
Word.Document wordDoc = thisApplication.Documents.Open(ref filename,ref
missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref
missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref
missing,ref missing,ref missing);
// Get the props
Microsoft.Office.Core.DocumentProperties docprops
=(Microsoft.Office.Core.DocumentProperties)
wordDoc.BuiltInDocumentProperties;
System.Diagnostics.Trace.WriteLine(docprops.Count) ; // THIS WORKS, output
is 30
} 5 2399
Thanks, I ended up doing it this way and it was very long winded, I wrote a
class that converts a COM collection to a .NET hashtable, but you would have
thought the office.word lib would work with the office core lib like it does
when you use the word application object that's is passed to the startup
method when you load the .NET assembly from the word document.
Steve
"Paul Stubbs [MS]" <ps*****@NoSpam.Microsoft.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl... Hi Steve,
There is a knowledge Base article that can show you how to get and set office document properties.
http://support.microsoft.com/?kbid=303296
Thanks, Paul Stubbs VSTO Program Manager
-- Please post questions to the newsgroup - everyone benefits. This post is provided "AS IS" with no warranties, and confers no rights Sample code subject to http://www.microsoft.com/info/cpyright.htm
Hi Steve,
Rather than automating Word for this, you might want instead to use an
ActiveX DLL which is available from Microsoft on a free download, which just
reads & writes document properties, and does nothing else. It is a good deal
faster than automatic Word for this purpose, particularly if you don't
already have a copy of Word open.
The accompanying sample code is VB5/6, but it shouldn't be that hard to
control it from C#. Take a look here
Dsofile.exe Lets You Edit Office Document Properties from Visual Basic and
ASP http://support.microsoft.com/?kbid=224351
--
Regards
Jonathan West - Word MVP http://www.multilinker.com
Please reply to the newsgroup
"Steve Drake" <Steve@_NOSPAM_Drakey.co.uk> wrote in message
news:uQ****************@TK2MSFTNGP12.phx.gbl... Thanks, I ended up doing it this way and it was very long winded, I wrote
a class that converts a COM collection to a .NET hashtable, but you would
have thought the office.word lib would work with the office core lib like it
does when you use the word application object that's is passed to the startup method when you load the .NET assembly from the word document.
Steve
"Paul Stubbs [MS]" <ps*****@NoSpam.Microsoft.com> wrote in message news:%2***************@TK2MSFTNGP11.phx.gbl... Hi Steve,
There is a knowledge Base article that can show you how to get and set office document properties.
http://support.microsoft.com/?kbid=303296
Thanks, Paul Stubbs VSTO Program Manager
-- Please post questions to the newsgroup - everyone benefits. This post is provided "AS IS" with no warranties, and confers no rights Sample code subject to http://www.microsoft.com/info/cpyright.htm
I have used that in the past, but... it doesent do bookmarks :(
Thanks
Steve
"Jonathan West" <jw***@mvps.org> wrote in message
news:OM**************@TK2MSFTNGP10.phx.gbl... Hi Steve,
Rather than automating Word for this, you might want instead to use an ActiveX DLL which is available from Microsoft on a free download, which
just reads & writes document properties, and does nothing else. It is a good
deal faster than automatic Word for this purpose, particularly if you don't already have a copy of Word open.
The accompanying sample code is VB5/6, but it shouldn't be that hard to control it from C#. Take a look here
Dsofile.exe Lets You Edit Office Document Properties from Visual Basic and ASP http://support.microsoft.com/?kbid=224351
-- Regards Jonathan West - Word MVP http://www.multilinker.com Please reply to the newsgroup
"Steve Drake" <Steve@_NOSPAM_Drakey.co.uk> wrote in message news:uQ****************@TK2MSFTNGP12.phx.gbl... Thanks, I ended up doing it this way and it was very long winded, I
wrote a class that converts a COM collection to a .NET hashtable, but you would have thought the office.word lib would work with the office core lib like it does when you use the word application object that's is passed to the startup method when you load the .NET assembly from the word document.
Steve
"Paul Stubbs [MS]" <ps*****@NoSpam.Microsoft.com> wrote in message news:%2***************@TK2MSFTNGP11.phx.gbl... Hi Steve,
There is a knowledge Base article that can show you how to get and set office document properties.
http://support.microsoft.com/?kbid=303296
Thanks, Paul Stubbs VSTO Program Manager
-- Please post questions to the newsgroup - everyone benefits. This post is provided "AS IS" with no warranties, and confers no
rights Sample code subject to http://www.microsoft.com/info/cpyright.htm
"Steve Drake" <Steve@_NOSPAM_Drakey.co.uk> wrote in message
news:eL**************@TK2MSFTNGP11.phx.gbl... I have used that in the past, but... it doesent do bookmarks :(
If you want the contents of the properties to be reflected wothin the
document, simply ensure that DOCPROPERTY fields are inserted where you
currently have bookmarks.
--
Regards
Jonathan West - Word MVP http://www.multilinker.com
Please reply to the newsgroup This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Nick Flandry |
last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my
development environment (Win2K server running IIS 5) and a test environment (also Win2K server
running IIS...
|
by: John Howard |
last post by:
Making the following call to a local MSAccess database works fine:
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
Dim intRows As Integer
Dim strSQL As String
Dim ds As New...
|
by: Hifni Shahzard |
last post by:
Hi,
I got a stored procedure, where it returns a value. But if I execute it. It
gives an error as "Invalid cast from System.Int32 to System.Byte.". To make
clear how do I execute this, below I'm...
|
by: Ken Ingram |
last post by:
I have been reading through all the MSDN docs on using the new Visual Studio
Tools for Microsoft Office Systems and have alot of things working in my
project. One thing I am stuggling with is how...
|
by: ©pEIO |
last post by:
I have installed the PIA of Microsoft Office 2003 and the installation was
succefully.
If I add the reference of Microsoft Excel 11.0, I see that the property
CopyLocal is False
and the assembly...
|
by: Tom Rahav |
last post by:
Dear All!
I use Visual Basic .NET 2003 and want to produce graphs by using Office
Chart 11.0.
I would like to provide this chart with data from an Office Spreadsheet 11.0
and I use the...
|
by: Steve Drake |
last post by:
All,
I am trying to open a word document and get all the properties using .NET
(c#), if I create the wordapp, call the correct methods I get invalid cast
(see code examples), but if I create a...
|
by: dennijr |
last post by:
ok, shell always used to be easy for me, now its starting to get annoying cause i dont know wats wrong
heres the simplist code possible:
Private Sub IExplorer_Click()
a = Shell("C:\Program...
|
by: vinci |
last post by:
Please help me out... i only have two weeks to do it...
here is my code:
Dim ex As New Object
Dim wb As Excel.Workbook
Dim sheet As Excel.Worksheet
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
| |