Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Navigate thru Large Text Files

Status
Not open for further replies.

ISPrincess

Programmer
Feb 22, 2002
318
US
I have a need to show the contents of (what could be) large text (audit) files in my asp pages (intranet).

I have tested most of the following code with regard to the usage of the filesystemobject - but am having issues trying to limit the display to say 100 - 500 lines per page then allowing some sort of user navigation.

I am pretty inexperienced with both asp and the filesystemobject, so if someone could find the 'problems' in my code and add the navigation to it - that would be great!

I need to be careful not to:
1. 'lock' the file as another system may be writing to it
2. 'lock' the user's pc [wink]
3. leave any files open
4. etc...

With regard to navigation thru the file - I am open to your suggestions, be it...
1. Pages ie: [1][2][3][end]
2. Prev / Next buttons
3. Treeview
4. anything - help!

Thank you ahead-of-time for all your help (as usual)
 
Of course, I forgot to include my existing code - sorry. Here it is:

Code:
<% @ Language=VBScript %>
<% Option Explicit 
'Set how many records per page we want
Const NumPerPage = 100

'Retrieve what page we're currently on
Dim CurPage
If Request.QueryString(&quot;CurPage&quot;) = &quot;&quot; then
	CurPage = 1 'We're on the first page
Else
	CurPage = Request.QueryString(&quot;CurPage&quot;)
End If
%>

<SCRIPT language=VBScript>
Dim oFS
Dim oTS
Dim oCS
Dim strFileName
Dim iResponse
Dim cCurPage

cCurPage = <%=CurPage%>

strFileName = &quot;C:\Temp\Dispatch.log&quot;

Set oFS = CreateObject(&quot;Scripting.FileSystemObject&quot;) 
If cCurPage = 1 then
	Set oCS = oFS.GetFile (&quot;C:\Temp\Dispatch.log&quot;)
	if oCS.size > 200000 then
		iResponse = msgbox(&quot;Size of file is &quot; & oCS.size & &quot; bytes. &quot; & (Chr(13) & Chr(10)) & _
						&quot;It is not Recommended to Load Files of this size.&quot; & (Chr(13) & Chr(10)) & _
						&quot;Press OK to Continue, Cancel to Abort File Load.&quot;,65,&quot;Alert&quot;)
		if iResponse = 1 then
			ProcessFile oFS,oTS, cCurPage
		else
			document.write &quot;Process Cancelled by User.&quot;
		end if
	end if
else
	ProcessFile oFS,oTS
end if

Sub ProcessFile (oFS, oTS, cCurPage)
	Dim Count
	
	Set oTS = oFS.OpenTextFile(&quot;C:\Temp\Dispatch.log&quot;,ForReading)

	'Set wfile = fs.OpenTextFile(&quot;\\Devserver\CDrive\Aurora\Audit\20020830\001333.rf&quot;)
	'Set wfile = fs.OpenTextFile(&quot;\\RFBanDC1\Data\Bannockburn\Audit\20021122\Dispatch.log&quot;)
	'filecontent = wfile.ReadAll 

	Count = 0
	Do While oTS.AtEndOfStream <> True and Count <= <%=NumPerPage%>
		'for lStartLn to lEndLn
			filecontent = oTS.ReadLine                
			document.writeln(&quot;<TABLE>&quot;)
			document.writeln(&quot;<TR>&quot;)
			'document.writeln(&quot;<TD noWrap>&quot; & Mid(Str1,10,5) & Mid(Str1,18,3) & &quot;  </TD>&quot;)
			document.writeln(&quot;<TD>&quot; & filecontent & &quot;</TD>&quot;)
			document.writeln(&quot;</TR>&quot;)
		'end for
	  document.writeln(&quot;</TABLE>&quot;)                                    
	  Count = Count + 1
	Loop                         
	
	  document.writeln(&quot;</TABLE>&quot;)                                    
	document.write &quot;Page &quot; & cCurPage
	
	'Display Next / Prev buttons
	if cCurPage > 1 then
		'We are not at the beginning, show the prev button
		document.Write(&quot;<INPUT TYPE=BUTTON VALUE=PREV ONCLICK=&quot;&quot;document.location.href='textfile.asp?curpage=&quot; & curpage - 1 & &quot;';&quot;&quot;>&quot;)
	End If

	if not oTs.AtEndOfStream then
		'We are not at the end, show a next button
		Document.Write(&quot;<INPUT TYPE=BUTTON VALUE=NEXT ONCLICK=&quot;&quot;document.location.href='textfile.asp?curpage=&quot; & curpage + 1 & &quot;';&quot;&quot;>&quot;)
	End If

	'ofs.Close
	oTS.close 
	
	Set oTS=nothing 
	Set oFS=nothing 
	
end sub

</SCRIPT>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top