Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

ASP.NET Forum


You are currently viewing our ASP.NET Forum as a guest. Please register to participate.
Login



Reply
beginner needs help cleaning up code
Old 10-20-2006, 06:44 AM beginner needs help cleaning up code
Junior Talker

Posts: 2
Trades: 0
I may be asking to much here but I am useing this asp page to read the contents of a folder and write it to a access db then write back as links. There are a lot of things I would like to do with it as I learn more. But what I need first is clean up the code some and get it to write to a html template. If I can do this I think I can make the link page look better. Here is the code that reads the folder.

Code:
 
<%@ LANGUAGE="VBSCRIPT" %>
<% Option Explicit %>
<!-- VSS generated file data
$Modtime: 10/19/2006 10:24a $
$Revision: 1 $
$Workfile: download.asp $
-->
<%
 On Error Resume Next
 
 Dim f, strDisplay, conn, Description, fc, fl, y, FileName, _
 posFile, g, rs, sql, machine
 
'----------Localization Variables-----------------
 Dim bckSlash, colon, semiColon, period, locfiledownloads, locHome, _
 locK, locSize, locDescription
 
 bckSlash = chr(92)
 colon = chr(58)
 semiColon = chr(59)
 period = chr(46)
 
 locfiledownloads = "downloads"
 locHome = "downloads"
 locK = " KB" 'File Size
 locSize = "Size "
 
'---------------Run Subs--------------
setSysObj
readDescriptions
'---------------Subs------------------
Sub setSysObj
 Set FileSystem=CreateObject("Scripting.FileSystemObject")
 Dim root, FileSystem, g, sc
  root = server.mappath(bckSlash)
 root = Trim(Left(root, instrRev(root, bckSlash)))
 root = root + "downloads"
 g = FileSystem.GetAbsolutePathName(root)
  Set f=FileSystem.GetFolder(g)
 Set sc = f.SubFolders
End Sub
Here is the code that reads the database.

Code:
 
Sub readDescriptions 'Read all file descriptions in downloads.mdb
 Dim strProvider, sql, rs, n, i
 strProvider="DRIVER=Microsoft Access Driver (*.mdb); DBQ=" & Server.MapPath(bckSlash + "iisadmin") & bckSlash + "downloads" + bckSlash + "downloads.mdb" + semiColon
 Set conn = Server.CreateObject("ADODB.Connection")
     conn.open strProvider,"",""
 sql = "SELECT FileList.FileName, FileList.FileDescription, FileList.FilePath FROM FileList ORDER BY FileList.FileName"
 Set rs = Server.CreateObject("ADODB.Recordset")
 rs.Open sql, conn, 3, 3
 If not rs.EOF Then
  rs.movelast 
  n = rs.recordcount - 1
  rs.movefirst
  For i = 0 to n
   strDisplay = strDisplay + rs.Fields("FileName").Value +  " " + rs.Fields("FileDescription").Value + semiColon
   rs.movenext
  Next
 End If
End Sub
%>
Here is the html and form that writes the links. This is what I think I need to change.

Code:
 
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft FrontPage 5.0">
<META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
<%
 call stylesheet
 Function writeFiles()
 DIM strFiles, FileSize
 'Read all file names in downloads
   Set fc = f.Files
  strFiles =  "<TABLE BORDER=0 cellspacing=0 cellpadding=1 width=""" & "90%" & """ height=""" & "100%" & """ class=bg0>"
 g = ".." + bckSlash + ".." + bckSlash + "downloads" + bckSlash
  For Each fl in fc
  y = y + 1
   FileName=fl.name
   If strDisplay <> "" Then
    posFile=instr(Ucase(strDisplay), Ucase(FileName))
    If posFile <> 0 Then
     Set rs = Server.CreateObject("ADODB.Recordset") 
     sql = "SELECT FileList.FileName, FileList.FileDescription, FileList.FilePath FROM FileList WHERE FileList.FileName ='" + FileName + "'"
     rs.Open sql, conn, 3, 3
     Description = rs.Fields("FileDescription").Value
    Else
     Description = ""
    End If
   End If
  If y Mod 2 <> 0 Then
   strFiles = strFiles & "<TR>"
  End If
  FileSize = Int((fl.size/1024) + .5)
  strFiles = strFiles & "<TD HEIGHT=10 WIDTH='50%'><IMG SRC='file.gif' WIDTH=13 HEIGHT=16 BORDER=0>&nbsp;&nbsp;"
  strFiles = strFiles & "<A HREF='" & g & fl.name & "'>" & fl.name & "<A/><BR>" & locSize & FileSize & locK & "<BR>" & Description & "</TD>"
  If y Mod 2 = 0 Then
   strFiles = strFiles & "</TR>"
  End If
  Next
  strFiles = strFiles & "</TABLE>"
  writeFiles = strFiles
 End Function
machine= Request.ServerVariables("SERVER_NAME") 
%>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TOPMARGIN="0" LEFTMARGIN="0">
<TABLE BORDER=0 cellspacing=0 cellpadding=5 width="100%" height="100%" class=bg0>
 <TR ALIGN="CENTER">
  <TD Rowspan="3" Width="50" Height="100%" class=bg1>&nbsp;&nbsp;&nbsp;</TD>
  <TD Rowspan="3" Width="50" Height="100%" class=bg2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
  <TD Height=65 Colspan=3 class=bg3>
   <FONT style='font-family:verdana;font-size:24pt'><%=locFiledownloads%></Font>
   <FORM NAME="frmHOME" METHOD="POST" ACTION="http://<%=machine%>/downloads.asp">
   
  </FORM>
  </TD>
 </TR>
 <TR ALIGN="CENTER"><TD>
<%
 response.write writeFiles()
%>
 </TD>
 </TR>
 <TR>
 <TD WIDTH="100%" HEIGHT="25">&nbsp;</TD>
 </TR>
</TABLE>
</BODY>
</HTML>
What I am going to try doing is seperate it out into three scripts and get it pick from a list of folders and maching db's. that will allow me to move files from one folder to another from a single asp page.
dvdljns is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Reply     « Reply to beginner needs help cleaning up code
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.07878 seconds with 12 queries