How to change MS Word data to byte[ ]

  • Thread starter Thread starter cgd
  • Start date Start date
C

cgd

hi,
i want to save the MS Word data (not the Word file) to a database,
so i copy the Word data to clipboard first,and then get the data to a
DataObject object, and then try the code below,


Formatter.Serialize(StreamTemp, dbObject); //but it can't be Serialized,
StreamTemp.Close();
Return StreamTemp.GetBuffer() ;



plz, thanks for any help
 
Try copying to the clipboard with DataFormat.Rtf .
Then you can copy out from clipboard and try casting to byte array.
Peter
 
You don't want to serialize the IDataObject but instead the actual
data. Use GetFormats() to identify the available formats and
GetData(format) to get the real data. Once you get the data, then you
can serialize that.

Note that some formats can generate a FatalExecutionEngineError which
can shut down your app and not even be caught with a try/catch so be
careful.

Formats supported by MS Word 2003 which can be retrieved in .NET 2.0:

Object Descriptor
Rich Text Format
HTML Format
System.String
UnicodeText
Text

And formats which generate the nasty error (at least in my testing):

EnhancedMetafile
MetaFilePict
Embed Source
Link Source
Link Source Descriptor
ObjectLink

When run in debugger I can get this info, but when run normally the
app just shuts down:

FatalExecutionEngineError was detected
Message: The runtime has encountered a fatal error. The address of the
error was at 0x79f1c184, on thread 0x608. The error code is
0xc0000005. This error may be a bug in the CLR or in the unsafe or
non-verifiable portions of user code. Common sources of this bug
include user marshaling errors for COM-interop or PInvoke, which may
corrupt the stack.

HTH,

Sam
 
Peter:
thank you very much,
i copy to clipboard with fromat RTF,
the i get the data from clipboard is string ,then i save the string to DB,
that's ok. thanks.:)
 
Thank you ,Sam. I get it.

Samuel R. Neff said:
You don't want to serialize the IDataObject but instead the actual
data. Use GetFormats() to identify the available formats and
GetData(format) to get the real data. Once you get the data, then you
can serialize that.

Note that some formats can generate a FatalExecutionEngineError which
can shut down your app and not even be caught with a try/catch so be
careful.

Formats supported by MS Word 2003 which can be retrieved in .NET 2.0:

Object Descriptor
Rich Text Format
HTML Format
System.String
UnicodeText
Text

And formats which generate the nasty error (at least in my testing):

EnhancedMetafile
MetaFilePict
Embed Source
Link Source
Link Source Descriptor
ObjectLink

When run in debugger I can get this info, but when run normally the
app just shuts down:

FatalExecutionEngineError was detected
Message: The runtime has encountered a fatal error. The address of the
error was at 0x79f1c184, on thread 0x608. The error code is
0xc0000005. This error may be a bug in the CLR or in the unsafe or
non-verifiable portions of user code. Common sources of this bug
include user marshaling errors for COM-interop or PInvoke, which may
corrupt the stack.

HTH,

Sam


------------------------------------------------------------
We're hiring! B-Line Medical is seeking .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.
 
I find Get the Word data as RTF string is biger than the word DOC file,
So, I'd better Save the word to database as a DOC file,
It's better Save the document to database in memory. than save it to disk
and then open as stream to Database,how to do this ?
thank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top