473,326 Members | 2,111 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,326 software developers and data experts.

Replacing strings within a word doc and convert back to byte[]

I am currently trying to replace certain strings, not
single characters, with other strings inside a word
document which is then sent to a browser as a binary
file. Right now, I read in the word file, convert the
FileStream into a string using Unicode encoding, then do a
replace, then convert the string back to a byte[] using
Unicode encoding which i then Response.WriteBinary(bytes)
to the browser. This works fine although the actual
replace is not working correctly. When I use UTF8 or
ASCII encoding the word document does not open correctly
in Word unfortunately. Anyone ever done this before? I
do not want to use the word component if possible or save
the word document back to disk if possible as its being
used as a template. Thank you so much!

Sincerely,
Christopher Beltran
VP Product Development, Passageways

P.O. Box 1950
West Lafayette, IN 47906

Telephone: (765) 497-8829
Direct Line: (765) 497-8831
Fax: (765) 497-8804
Email: ch***@passageways.net
Nov 15 '05 #1
2 3362
A Word file doesn't consist entirely of char's, so you can't load it into a
string without corrupting it. You might be successful loading it into a byte
array and doing the search and replace directly on the byte array, but you'd
have to come up with your own search and replace code because String.Replace
wouldn't be available.

I don't know the Word file format so there still may be problems with this
approach. For example, if Word keeps a checksum of the document to detect
corruption you'd have to update the checksum.
"Christopher Beltran" <ch***@passageways.net> wrote in message
news:05****************************@phx.gbl...
I am currently trying to replace certain strings, not
single characters, with other strings inside a word
document which is then sent to a browser as a binary
file. Right now, I read in the word file, convert the
FileStream into a string using Unicode encoding, then do a
replace, then convert the string back to a byte[] using
Unicode encoding which i then Response.WriteBinary(bytes)
to the browser. This works fine although the actual
replace is not working correctly. When I use UTF8 or
ASCII encoding the word document does not open correctly
in Word unfortunately. Anyone ever done this before? I
do not want to use the word component if possible or save
the word document back to disk if possible as its being
used as a template. Thank you so much!

Sincerely,
Christopher Beltran
VP Product Development, Passageways

P.O. Box 1950
West Lafayette, IN 47906

Telephone: (765) 497-8829
Direct Line: (765) 497-8831
Fax: (765) 497-8804
Email: ch***@passageways.net

Nov 15 '05 #2

"Christopher Beltran" <ch***@passageways.net> wrote in message
news:05****************************@phx.gbl...
I am currently trying to replace certain strings, not
single characters, with other strings inside a word
document which is then sent to a browser as a binary
file. Right now, I read in the word file, convert the
FileStream into a string using Unicode encoding, then do a
replace, then convert the string back to a byte[] using
Unicode encoding which i then Response.WriteBinary(bytes)
to the browser. This works fine although the actual
replace is not working correctly. When I use UTF8 or
ASCII encoding the word document does not open correctly
in Word unfortunately. Anyone ever done this before? I
do not want to use the word component if possible or save
the word document back to disk if possible as its being
used as a template. Thank you so much!


Hi Christopher,

The easiest way to work with Word docs is via COM Interop/VS.NET Tools for
Office or a 3rd party component, such as JiSys WordReports.

Here's the link to VS.NET Tools for Office:

http://msdn.microsoft.com/vstudio/office/default.aspx

Here's a link to JiSys:

http://www.jisys.com/

And a review:

http://www.csharp-station.com/Articles/WordReports.aspx

Joe
--
http://www.csharp-station.com
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Ravi | last post by:
Hi, I have about 200GB of data that I need to go through and extract the common first part of a line. Something like this. >>>a = "abcdefghijklmnopqrstuvwxyz" >>>b = "abcdefghijklmnopBHLHT"...
12
by: Brent W. Hughes | last post by:
I kind of hate to have to convert a string into a list, manipulate it, and then convert it back into a string. Why not make strings mutable?
13
by: yaipa | last post by:
What would be the common sense way of finding a binary pattern in a ..bin file, say some 200 bytes, and replacing it with an updated pattern of the same length at the same offset? Also, the...
13
by: Thomas Zhu | last post by:
Hello, I know the difference between the two definations. But I do not know where are they in the memory. would someone tell me ? char s={"good", "morning"}; // at stack? char *t = {"good",...
5
by: Maury Markowitz | last post by:
I have a byte returned from a DLL that contains n c-style strings inside it. Any suggestions on how to easily pull them out into a string? Encoding helps with a single byte array (although easily...
4
by: Andrew Inwards | last post by:
Is it possible to save a MS Word document in a string? I suspect not because Ive tried saving it in using various encoding formats and it always gets corrupted. Thanks Andrew
12
by: Adam J. Schaff | last post by:
I am writing a quick program to edit a binary file that contains file paths (amongst other things). If I look at the files in notepad, they look like: ...
89
by: scroopy | last post by:
Hi, I've always used std::string but I'm having to use a 3rd party library that returns const char*s. Given: char* pString1 = "Blah "; const char* pString2 = "Blah Blah"; How do I append...
7
by: aine_canby | last post by:
Hi, Im totally new to Python so please bare with me. Data is entered into my program using the folling code - str = raw_input(command) words = str.split() for word in words:
0
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
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...
1
isladogs
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...
0
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...
1
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...
1
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....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.