473,397 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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 2848
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Paul | last post by:
Hi, (First apologies if this is not the most relevant place to post this but I wasn't sure of where was and I am writing my app in VB.) I'm attempting to parse a binary file for which I have...
13
by: Bryan Parkoff | last post by:
I have two variables: "char A" and "short B". I can be able to convert from A to B using explicit case conversion with no problem like "B = short (A);". Right now, I have two variables: "char T"...
12
by: Oliver Knoll | last post by:
Ok, I've searched this group for Big/Little endian issues, don't kill me, I know endianess issues have been discussed a 1000 times. But my question is a bit different: I've seen the follwing...
1
by: Sisnaz | last post by:
I'm sending a message from VB.net (2003) to a C++ app via TCP sockets of values 1 to 328. The message is a WORD value where I have to manage both bytes for the WORD. I'm sending and receiving data...
1
by: K B | last post by:
I'm using the following in .NET to save a Word document to a SQL image column: Dim iImageSize As Integer = FileUpload.PostedFile.ContentLength Dim picbyte() As Byte = New Byte(iImageSize) {}...
2
by: Andy | last post by:
Hi, I have an XML document that uses namespaces (it is from a Word 2007 file). I want to retrieve all the "t" elements that belong to the "w" namespace (<w:t>) using XPath from VB.NET 2003 (.NET...
2
by: koraykazgan | last post by:
Hi all, I am using a WebService in ASP.Net 2.0 to retrieve Data in XTHML format. I want to put this data in a Word Document and send this document to the client. Till now, I just used...
6
by: artist | last post by:
Hi all, I have the following: byte msgData = new byte; ushort aaa = 0xFFFA; Now I would like to store that variable aaa in the array
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.