473,748 Members | 6,664 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.WriteB inary(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***@passagewa ys.net
Nov 15 '05 #1
2 3411
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.
"Christophe r Beltran" <ch***@passagew ays.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.WriteB inary(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***@passagewa ys.net

Nov 15 '05 #2

"Christophe r Beltran" <ch***@passagew ays.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.WriteB inary(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
5772
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" >>>c = extract(a,b) >>>print c "abcdefghijklmnop"
12
2322
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
15254
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 pattern can occur on any byte boundary in the file, so chunking through the code at 16 bytes a frame maybe a problem. The file itself isn't so large, maybe 32 kbytes is all and the need for speed is not so great, but the need for accuracy in the...
13
2123
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", "morning"}; // at heap? thanks in advance.
5
1735
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 enough), but doesn't parse out runs of them. Looping over the bytes looking for x00's strikes me as too 1960s. Is there some helper that does this?
4
3176
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
5918
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: <gibberish>file//g:\pathtofile1<gibberish>file//g:\pathtofile2<gibberish> etc. I want to remove the "g:\" from the file paths. I wrote a console app that successfully reads the file and writes a duplicate of it, but fails for some reason to do the "replacing" of the "g:\". The code...
89
5141
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 the contents of pString2 to pString? (giving "Blah Blah Blah")
7
3513
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
9534
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9316
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9241
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8239
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6793
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4867
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2211
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.