473,593 Members | 2,925 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Counting lines/characters in an uploaded .DOC/.RTF file using ASP.NET

j
Hi,
I've been trying to do line/character counts on documents that are
being uploaded. As well as the "counting" I also have to remove
certain sections from the file.
So, firstly I was working with uploaded MS WORD .doc files. Using code
like that below:

strLine = sr.ReadLine
While Not IsNothing(strLi ne) 'Not eof
If Trim(strLine) <> "" Then 'Not blank
'increment counter & capture line text
lc += 1
sbFileContent.A ppend(strLine + vbCr) 'Put CR into string to mark
line break
End If
strLine = sr.ReadLine
End While
sr.Close()

and with a subsequent count on the number of vbCr in the
string-builder contents (sbFileContent) I was hoping to count the
number of "visible" & non-blank lines (and thus characters) in the
file.

My first problem:
If you type in WORD WITHOUT using any line break characters (vbCr,
vbLf, vbCrLf etc), the typing naturally wraps at the edge of the page
so that on visual inspection a document might have 1 paragraph
consisting of 8 lines BUT in fact what you actually have is 1
continuous string with no line breaks. I guess I'm wondering how can
you count lines in a WORD file like its native line counter but
without using WORD on the server!
How does WORD do it anyway? Does it calculate the number of lines by
dividing the total number of characters in the file by the width of
the page in characters????

My second problem:
I have to edit the file to remove some sections. I need to edit the
file and re-save it which, when the file is a MS WORD .doc file, is
problematic considering I don't have WORD on the server. The file just
gets corrupted and when I have to open it later I just get gibberish.

So, I thought about using an RTF file saved from WORD as the uploaded
document. Now, the benefits of RTF is that I can definitely do the
search & replace function and resave the docuemnt WITHOUT causing any
corruption of the document.
However, I have much the same "line counting" problems as I had with
WORD except that now I even have the RTF formatting markup do deal
with which is in the actual content of the file. So, I guess I'm
wondering how to do line counting of visible, non-blank lines in an
RTF while ignoring the RTF markup. Again I'm gonna have the same
problems with the counting of lines where word wrapping is what is
responsible for breaking of a continuous paragraph into a number of
lines.

So, I need a solution that will allow me to count the number of
visible lines in either a WORD or RTF file AND a suggestion of how to
edit (Search/Replace & Save) that file, after the counting process!!!

Would anyone have any suggestions, bright ideas, hacks, references,
code, sleep they'd like to give me I'd be very grateful!
Thanks for listening,
J
Nov 17 '05 #1
1 6913
I would suggest you post this question to the Word/Office newsgroups. This
is not an ASP.Net-related question.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Big things are made up of
lots of little things.

"j" <j_**********@h otmail.com> wrote in message
news:16******** *************** ***@posting.goo gle.com...
Hi,
I've been trying to do line/character counts on documents that are
being uploaded. As well as the "counting" I also have to remove
certain sections from the file.
So, firstly I was working with uploaded MS WORD .doc files. Using code
like that below:

strLine = sr.ReadLine
While Not IsNothing(strLi ne) 'Not eof
If Trim(strLine) <> "" Then 'Not blank
'increment counter & capture line text
lc += 1
sbFileContent.A ppend(strLine + vbCr) 'Put CR into string to mark
line break
End If
strLine = sr.ReadLine
End While
sr.Close()

and with a subsequent count on the number of vbCr in the
string-builder contents (sbFileContent) I was hoping to count the
number of "visible" & non-blank lines (and thus characters) in the
file.

My first problem:
If you type in WORD WITHOUT using any line break characters (vbCr,
vbLf, vbCrLf etc), the typing naturally wraps at the edge of the page
so that on visual inspection a document might have 1 paragraph
consisting of 8 lines BUT in fact what you actually have is 1
continuous string with no line breaks. I guess I'm wondering how can
you count lines in a WORD file like its native line counter but
without using WORD on the server!
How does WORD do it anyway? Does it calculate the number of lines by
dividing the total number of characters in the file by the width of
the page in characters????

My second problem:
I have to edit the file to remove some sections. I need to edit the
file and re-save it which, when the file is a MS WORD .doc file, is
problematic considering I don't have WORD on the server. The file just
gets corrupted and when I have to open it later I just get gibberish.

So, I thought about using an RTF file saved from WORD as the uploaded
document. Now, the benefits of RTF is that I can definitely do the
search & replace function and resave the docuemnt WITHOUT causing any
corruption of the document.
However, I have much the same "line counting" problems as I had with
WORD except that now I even have the RTF formatting markup do deal
with which is in the actual content of the file. So, I guess I'm
wondering how to do line counting of visible, non-blank lines in an
RTF while ignoring the RTF markup. Again I'm gonna have the same
problems with the counting of lines where word wrapping is what is
responsible for breaking of a continuous paragraph into a number of
lines.

So, I need a solution that will allow me to count the number of
visible lines in either a WORD or RTF file AND a suggestion of how to
edit (Search/Replace & Save) that file, after the counting process!!!

Would anyone have any suggestions, bright ideas, hacks, references,
code, sleep they'd like to give me I'd be very grateful!
Thanks for listening,
J

Nov 17 '05 #2

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

Similar topics

6
3087
by: Dale Atkin | last post by:
As part of a larger project, I need to be able to count the number of lines in a file (so I know what to expect). Anyways, I came accross the following code that seems to do the trick, the only thing is, I'm not 100% sure what it is doing, or how. #include<iostream> #include<fstream> main(int argc, char *argv) {
1
1365
by: jabailo | last post by:
Which would be faster for counting lines in a StreamReader: (a) iterate through a file using .ReadLine() and adding to a counter, i++ (b) doing a .ReadToEnd() and then using an IndexOf() method to count the occurances of \r\n (c) doing a .ReadToEnd() and using a RegEx to count the number of occurances of \r\n
5
5304
by: Neo | last post by:
Hello: I am receiving a Binary File in a Request from a application. The stream which comes to me has the boundary (Something like "---------------------------39<WBR>­0C0F3E0099" without the quotes), and also some more text like this and file name (e.g. "Content-Disposition: form-data; name="upload_file"; filename="C:\testing\myfile.da<WBR>­t" Content-Type: application/octet-stream")
3
1387
by: Brent | last post by:
Say that I have a text box that holds 5 lines of text. If the user enters ten text lines, I want the first four lines of text displayed, followed by a "More" hyperlink. The link will pop up another page to display the rest of the text. The problem is that I don't know how to count lines. I can count characters, but this solution fails spectacularly when it encounters the characters "<br/>" (which should be counted as a full line, of...
5
7680
by: andy.lee23 | last post by:
hi im having trouble counting lines in a text file, i have the following code int node1, node2, i; char name; float value; ifstream fin; fin.open(OpenDialog1->FileName.c_str()); i=1;
4
8431
by: bigbagy | last post by:
Notes The programs will be compiled and tested on the machine which runs the Linux operating system. V3.4 of the GNU C/C++ compiler (gcc ,g++) must be used. A significant amount coding is needed for this assignment. 1.Counting Words in C++ Problem: Write an elegant C++ program to count the number of times each word occurs in a file. A word is defined as a sequence of characters surrounded by whitespace. Case is not important, so...
7
2094
by: peraklo | last post by:
Hello, there is another problem i am facing. i have a text file which is about 15000 lines big. i have to cut the last 27 lines from that file and create a new text file that contans those 27 lines. and after that save both of those files... since that is a big block of text (15000 lines) i thint that it is a big job to look for a keyword... so my question is this exactly: how do i do this:
8
5265
by: xiaolim | last post by:
i making a simple program to count the different kinds of characters in a text file and then display them out, however i only manage to count the total numbers of characters. #include <iostream> #include <cstring> #include <fstream> #include <conio.h> #include<stdio.h> #include <string.h>
12
9727
by: Punkis | last post by:
Hi all, I have a problem with my php and mysql project. I use an auctions software, named phpauction for my project. I import into my database with utf8 encodingm and I can see the greek letters inside the fields. The problem is that when i go to the site for the results, I get question marks instead of the greek characters. I have searched a lot, and i found that there is a solution by adding mysql_query("SET NAMES utf8") after...
0
7871
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8236
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
8366
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
7995
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
8227
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...
1
5735
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
3893
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1467
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1202
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.