PC Review


Reply
Thread Tools Rate Thread

How to change MS Word data to byte[ ]

 
 
cgd
Guest
Posts: n/a
 
      24th Apr 2007
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



 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      24th Apr 2007
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
>
>
>
>

 
Reply With Quote
 
Samuel R. Neff
Guest
Posts: n/a
 
      24th Apr 2007

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" <(E-Mail Removed)> 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
>
>


 
Reply With Quote
 
cgd
Guest
Posts: n/a
 
      24th Apr 2007
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]" <(E-Mail Removed)> 写入消息
news:A53DAFE4-19CC-45FB-B94C-(E-Mail Removed)...
> 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
>>
>>
>>
>>



 
Reply With Quote
 
cgd
Guest
Posts: n/a
 
      24th Apr 2007
Thank you ,Sam. I get it.

"Samuel R. Neff" <(E-Mail Removed)> ????
news:(E-Mail Removed)...
>
> 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" <(E-Mail Removed)> 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
>>
>>

>



 
Reply With Quote
 
cgd
Guest
Posts: n/a
 
      24th Apr 2007
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]" <(E-Mail Removed)> 写入消息
news:A53DAFE4-19CC-45FB-B94C-(E-Mail Removed)...
> 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
>>
>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I change the location name for a data source in Word 07? Dolsne Microsoft Access 1 27th Oct 2009 10:59 PM
i want to change data in word to excel VINOD DHANAK Microsoft Access Queries 2 4th Apr 2009 04:48 AM
How to change a String into a Byte to show a ASCII Character Tobi Microsoft VB .NET 5 13th Mar 2007 08:09 PM
Does really List<byte> keep data in one block like byte[]? Hyun-jik Bae Microsoft C# .NET 1 4th Mar 2007 07:01 PM
How can I map byte[] data to struct data (preferably using managed code) Marquee Microsoft C# .NET 1 5th Aug 2004 10:47 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:44 PM.