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

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

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

    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(strLine) 'Not eof
    If Trim(strLine) <> "" Then 'Not blank
    'increment counter & capture line text
    lc += 1
    sbFileContent.Append(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
    j Guest

  2. Similar Questions and Discussions

    1. Linked file uploaded - link still points to local file
      Hi, We are faced with a strange problem in one of your Contribute sites: 2 users reported problems when linking and uploading files: user...
    2. Where is the uploaded file?
      When I upload a file by use of say <form action="<? $_PHP_SELF ?>" METHOD="GET" ENCTYPE="multipart/form-data"> File to be uploaded: <input...
    3. read lines of file without parsing the lines
      Hello! Currently i have a logfile which tracks a certain feature on my server. Every time the feature accurs my script appends a line in the...
    4. Counting characters in a string
      I have several isbn's that are eather 10 or 12 charcters long. I need to insert a dot . after the fifth character if it is 10 long, and after the...
    5. how to read japanese characters (multilingual characters) from a text file and save them in Access database ???
      HI All i m trying to read a text file, having some japanese characters and saved as UTF-8 encoding. I m using ASP,FSO ... my code is below,...
  3. #2

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

    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
    [url]http://www.takempis.com[/url]
    Big things are made up of
    lots of little things.

    "j" <j_mcmullin76@hotmail.com> wrote in message
    news:1603d3ce.0307220740.1037a9c2@posting.google.c om...
    > 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(strLine) 'Not eof
    > If Trim(strLine) <> "" Then 'Not blank
    > 'increment counter & capture line text
    > lc += 1
    > sbFileContent.Append(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

    Kevin Spencer Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139