469,631 Members | 1,218 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,631 developers. It's quick & easy.

How to change MS Word data to byte[ ]

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

Apr 24 '07 #1
5 2698
Try copying to the clipboard with DataFormat.Rtf .
Then you can copy out from clipboard and try casting to byte array.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"cgd" wrote:
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

Apr 24 '07 #2

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.
On Tue, 24 Apr 2007 18:10:50 +0800, "cgd" <xg@163.comwrote:
>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

Apr 24 '07 #3
cgd
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.:)

"Peter Bromberg [C# MVP]" <pb*******@yahoo.yabbadabbadoo.com写入消息
news:A5**********************************@microsof t.com...
Try copying to the clipboard with DataFormat.Rtf .
Then you can copy out from clipboard and try casting to byte array.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"cgd" wrote:
>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


Apr 24 '07 #4
cgd
Thank you ,Sam. I get it.

"Samuel R. Neff" <sa********@nomail.com????
news:6m********************************@4ax.com...
>
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.
On Tue, 24 Apr 2007 18:10:50 +0800, "cgd" <xg@163.comwrote:
>>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


Apr 24 '07 #5
cgd
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.

"Peter Bromberg [C# MVP]" <pb*******@yahoo.yabbadabbadoo.com写入消息
news:A5**********************************@microsof t.com...
Try copying to the clipboard with DataFormat.Rtf .
Then you can copy out from clipboard and try casting to byte array.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"cgd" wrote:
>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


Apr 24 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by Bryan Parkoff | last post: by
1 post views Thread by Sisnaz | last post: by
6 posts views Thread by artist | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.