Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Okay you ASP experts...

Posted on 1999-07-30
18
Medium Priority
?
156 Views
Last Modified: 2013-12-25
Let's say I have a document that is 890k.  Within that document I have 20 or so <A NAME="myName">myName</A> tags forming different sections.  Is there an ASP method to send a portion of that document, say 20k at at time, and then dynamically writing a link to the next 20k and so on?

The catch is that if the 20k is reached in between the anchor tags, I need to include entire sections of the anchor, i.e. not cut it off.

More points possible.

Kurt
0
Comment
Question by:kmartin7
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 7
  • 3
18 Comments
 
LVL 4

Expert Comment

by:siabod
ID: 1864551
Yes you can if you do it like this :

<---begining of file--->
<%
MySegment=request("PSegemnt")

If MySegment="1" then

 code...code...code
 %>
  <A HREF="thispagename.asp?PSegment=2"
 <%
End If

If MySegement="2" then

 code...code...code
 %>
   <A HREF="thispagename.asp?PSegment=3"
 <%
End If

etc,etc...

%>
<---End of file--->

What you do is you cut your code in little segments and rerun the same file with a link to another segment...

I hope this is what you want....otherwise just reject the answer...
0
 
LVL 11

Author Comment

by:kmartin7
ID: 1864552
I was more or less looking for something that acted upon file size (send 20K with a link to the next 20k or so) rather than breaking up into segments.  That is what I am trying to avoid.

Thanks anyway,

Kurt
0
 
LVL 4

Expert Comment

by:siabod
ID: 1864553
i'm affraid that's not possible, the script needs to be run at once or in little pieces and little pieces can only be achieved by cutting the script up in little pieces or loading the script in little pieces...

but i'm curious on what other experts have to say about it...
0
Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

 
LVL 11

Author Comment

by:kmartin7
ID: 1864554
Me too.  I didn't think it was possible, I just wanted to put out feelers before I give up on the idea.

Kurt
0
 
LVL 4

Expert Comment

by:siabod
ID: 1864555
Any particulair reason you have for such a thing?
the server giving time out errors?
you can force that to be longer...
0
 
LVL 25

Expert Comment

by:clockwatcher
ID: 1864556
The following will do what you ask.  It would need a lot more testing before I actually used it live somewhere, but it's a start.

It assumes its name is readpage.asp and the params it takes are as follows:

  filename:  full path to file that you want to serve (url-encoded)
  previousblocks:  how many blocks you've already read
  blocks:  number of blocks to read
  blocksize:  size of the block to read

So for 20K chunks with a file called c:\path\mylargefile.htm, you'd call it with something like the below:
 
  <a href="readpage.asp?filename=<%=server.urlencode("c:\path\mylargefile.htm")%>&previousblocks=0&blocksize=256&blocks=80">Chunky File</a>



-----

<%@ Language=VBScript %>

<% 'I like my files chunky

filename = Request.QueryString("filename")
blocksize = Request.QueryString("blocksize")
blocks = Request.QueryString("blocks")
previousblocks = Request.QueryString("previousblocks")

set oFile = server.CreateObject("Scripting.FileSystemObject")
set largeFile = oFile.OpenTextFile(filename, 1)

for i = 1 to previousblocks
  garbage = largeFile.read(blocksize)
next

blocksread = 0
for i = 1 to blocks
  pageSource = pageSource & largeFile.read(blocksize)
  blocksread = blocksread + 1
  if largeFile.AtEndOfStream then exit for
next

morepages = not(largeFile.AtEndOfStream)
largeFile.close

do
      lastLinkStart = 0
      do
            previousLinkStart = lastLinkStart
            lastLinkStart = instr(lastLinkStart+1, pageSource, "<a")
      loop while lastLinkStart <> 0
      lastLinkStart = previousLinkStart

      lastLinkEnd = 0
      do
            previousLinkEnd = lastLinkEnd
            lastLinkEnd = instr(previousLinkEnd + 1, pageSource, "</a")
      loop while lastLinkEnd <> 0
      lastLinkEnd = previousLinkEnd

      if lastLinkStart > lastLinkEnd then 'back it up a block
            pageSource = left(pageSource, len(pageSource) - blocksize)
            blocksread = blocksread - 1
      end if
      
loop while (blocksread > 0) and (lastLinkStart > lastLinkEnd)

nextblock = blocksread + previousblocks
 
%>
<HTML>
<HEAD>
</HEAD>
<BODY>
<% if blocksread = 0 then %>
Error:  Your data retrieved has an open anchor tag with no way to backtrack with the blocksize and number of blocks you've set up.
<% else %>
<%=pageSource%>
<BR><BR>
<a href="readpage.asp?filename=<%=server.urlencode(filename)%>&previousblocks=<%=nextblock%>&blocksize=<%=blocksize%>&blocks=<%=blocks%>">Next Page</a>
<% end if %>
</BODY>
</HTML>
0
 
LVL 25

Expert Comment

by:clockwatcher
ID: 1864557
The following will do what you ask.  It would need a lot more testing before I actually used it live somewhere, but it's a start.

It assumes its name is readpage.asp and the params it takes are as follows:

  filename:  full path to file that you want to serve (url-encoded)
  previousblocks:  how many blocks you've already read
  blocks:  number of blocks to read
  blocksize:  size of the block to read

So for 20K chunks with a file called c:\path\mylargefile.htm, you'd call it with something like the below:
 
  <a href="readpage.asp?filename=<%=server.urlencode("c:\path\mylargefile.htm")%>&previousblocks=0&blocksize=256&blocks=80">Chunky File</a>



-----

<%@ Language=VBScript %>

<% 'I like my files chunky

filename = Request.QueryString("filename")
blocksize = Request.QueryString("blocksize")
blocks = Request.QueryString("blocks")
previousblocks = Request.QueryString("previousblocks")

set oFile = server.CreateObject("Scripting.FileSystemObject")
set largeFile = oFile.OpenTextFile(filename, 1)

for i = 1 to previousblocks
  garbage = largeFile.read(blocksize)
next

blocksread = 0
for i = 1 to blocks
  pageSource = pageSource & largeFile.read(blocksize)
  blocksread = blocksread + 1
  if largeFile.AtEndOfStream then exit for
next

morepages = not(largeFile.AtEndOfStream)
largeFile.close

do
      lastLinkStart = 0
      do
            previousLinkStart = lastLinkStart
            lastLinkStart = instr(lastLinkStart+1, pageSource, "<a")
      loop while lastLinkStart <> 0
      lastLinkStart = previousLinkStart

      lastLinkEnd = 0
      do
            previousLinkEnd = lastLinkEnd
            lastLinkEnd = instr(previousLinkEnd + 1, pageSource, "</a")
      loop while lastLinkEnd <> 0
      lastLinkEnd = previousLinkEnd

      if lastLinkStart > lastLinkEnd then 'back it up a block
            pageSource = left(pageSource, len(pageSource) - blocksize)
            blocksread = blocksread - 1
      end if
      
loop while (blocksread > 0) and (lastLinkStart > lastLinkEnd)

nextblock = blocksread + previousblocks
 
%>
<HTML>
<HEAD>
</HEAD>
<BODY>
<% if blocksread = 0 then %>
Error:  Your data retrieved has an open anchor tag with no way to backtrack with the blocksize and number of blocks you've set up.
<% else %>
<%=pageSource%>
<BR><BR>
<a href="readpage.asp?filename=<%=server.urlencode(filename)%>&previousblocks=<%=nextblock%>&blocksize=<%=blocksize%>&blocks=<%=blocks%>">Next Page</a>
<% end if %>
</BODY>
</HTML>
0
 
LVL 25

Expert Comment

by:clockwatcher
ID: 1864558
Sorry for the double post and the lousy indentation.  The tabs got stripped out and the post was an accidental refresh.  

BTW, I forgot to include a check at the bottom of the script to see if more pages are actually available (right now it's assuming that there are no matter what)--  Like I said the script would need some work, but basically I think it gives you the idea.
0
 
LVL 11

Author Comment

by:kmartin7
ID: 1864559
I'll check it out sometime this weekend.  It looks promising! =)

Thanks,

Kurt
0
 
LVL 11

Author Comment

by:kmartin7
ID: 1864560
clockwatcher,

I am a little confused about the following line:

set largeFile = oFile.OpenTextFile(filename, 1)

Could you explain a little?

Kurt
0
 
LVL 25

Expert Comment

by:clockwatcher
ID: 1864561
Sure,

The following line:

   set oFile = server.CreateObject("Scripting.FileSystemObject")

creates a FileSystemObject-- obviously :-)

One of the methods of a FileSystemObject is OpenTextFile which takes the filename to open and the method (read-only, write, append, etc) for opening it as parameters and returns a TextStream Object.  So the following line:

  set largeFile = oFile.OpenTextFile(filename, 1)

Sets "largeFile" to the returned TextStream object represented by the open file called "filename" in ReadOnly mode "1"

---
For more detail on the FileSystemObject and TextSream objects, you can check out the intro at:
  http://msdn.microsoft.com/scripting/default.htm?/scripting/vbScript/doc/vbsfsotutor.htm

Actually, after looking at the bazillion or so answers you've given in the javascript realm, you may prefer to write your ASP in javascript.  If so, take a look at the following instead:

http://msdn.microsoft.com/scripting/default.htm?/scripting/JScript/doc/jsfsotutor.htm


If you've got any more questions or need any help let me know.
0
 
LVL 11

Author Comment

by:kmartin7
ID: 1864562
I'm trying to learn VBScript with ASP, that is why I'm asking...=)

I get an error on this line, and I cannot figure out why.  At first I thought that it needed a *.txt file to read from, but I assume that it will open an ASP ASCII file since you included it in the code.  Here is the error:

Server object error 'ASP 0177 : 800a0035'

Server.CreateObject Failed

/readpage.asp, line 12

00000000

Originally, I thought the error came from the setting oFile, because that is when the Server.CreateObject method occurs.  But line 12 is the set LargeFile line.  Any input?


I am going to go out and buy Beginning Active Server Pages 2 soon.  I have heard it is good to learn from.

Kurt
0
 
LVL 25

Expert Comment

by:clockwatcher
ID: 1864563
Just guessing off the top of my head, but perhaps the file you're trying to open doesn't exist.  It should be the actual location of the file within the file system (including the full path).  Not the virtual path.

I'll run a test and see what I get if I try to open a non-existent file.

0
 
LVL 25

Expert Comment

by:clockwatcher
ID: 1864564
Just ran a test and that's the error I get if I try to open a file that doesn't exist.  Hopefully, that explains the problem you're having.

Why bother with VBScript?  I guess it's just something else to play with.  IMHO, JScript is a lot more feature-rich than VBScript.  Neither comes anywhere near PerlScript, but I guess if you've got to work with a team of ASP developers nursed on VB, then it's something you gotta know.  Plus all the ASP demos and documentation are done in VBScript.

The best book I've seen on ASP is WROX's "Professional Active Server Pages".  I've got the old original version, back when ASP was still an optional add-in to IIS 3.0, and I already knew VBScript at the time so I don't really know how well it would work without knowing VB.  But, in general, I've found WROX puts out high quality stuff.

I also usually like O'Reilly's stuff.  They've got "ASP in a Nutshell".  Without a good grasp of VBScript, it probably wouldn't be one to start with, but for reference you usually can't go wrong with O'Reilly's.
0
 
LVL 11

Author Comment

by:kmartin7
ID: 1864565
It is more or less to make myself more marketable.  Looking around the job market, seems they want JScript AND VBScript for ASP.  I don't exactly know why...

I put the absolute path to the file, starting with c:\inetpub\wwwroot\filename.asp.  Is this the correct syntax or do I need to place the file protocol?

Kurt
0
 
LVL 25

Expert Comment

by:clockwatcher
ID: 1864566
The absolute path should be the correct syntax.

I posted a sample at:

  http://www.yahright.com/ee/10189029/

It demonstrates reading just part of a file (the first form), listing the directory contents (the second pull down is built dynamically), and reading a full file and displaying it (the view ASP source code page).

0
 
LVL 11

Author Comment

by:kmartin7
ID: 1864567
Thanks!  I had a single character missing from the path!  I HATE it when something so easy causes the problem!

Please answer...

Kurt
0
 
LVL 25

Accepted Solution

by:
clockwatcher earned 400 total points
ID: 1864568
The easiest stuff is always the hardest to find. :-)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
Suggested Courses

661 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question