Solved

ASP Text Parsing Routines/Variables Not Refreshing?

Posted on 2001-09-01
2
254 Views
Last Modified: 2010-08-05
I'm using the FSO object to create a virtual directory on an IIS server which points to
the location on the remote server whose directory structure I wanted to access.  I put my ASP page in
the root directory of the remote server and since it was a virtual directory within an IIS Web Folder,
it works.  

My Function called FolderName does not return an accurate number for strLength for each folder you drill
down to ... it seems to not be refreshing.  Is there something else I need to do to get this to work?
 I'm trying to capture only the folder names (structure) while the user drills down through the folders
so when they click on a document, the browser will open it correctly (HTMLEncoded) with the write path.

<%@ Language=VBScript %>
<%

Option Explicit
Dim myPath
Dim myFolderName
Dim testvar1
Dim testvar2


Dim giCount
Dim gvAttributes

Dim Ext

Dim ScriptFolder
Dim     FolderPath

'Tabed to show relation.
Dim     FileSystem
Dim          Drives
Dim               Drive
Dim          Folders
Dim               Folder
Dim               SubFolders
Dim                    SubFolder
Dim               Files
Dim                    File

Dim BgColor, BackgroundColor


'For anything on this page to work, the user must have the run-time
'dll's installed on the server.  Lets try to create the object
'and see what happends.
Set FileSystem = Server.CreateObject("Scripting.FileSystemObject")

'Get File List Location
FolderPath = Request.QueryString("FolderPath")

If FolderPath = "" Then
     'Not folder path specified.  Lets use the one that this script is
     'located in.
     FolderPath = Request.ServerVariables("PATH_TRANSLATED")
     'FolderPath = Request.ServerVariables("//pcdmweb1/isodoc/")
End If

'Remove any files that are included as the path.
FolderPath = ParseFolder(FolderPath)

ScriptFolder = ParseFolder(Request.ServerVariables("PATH_TRANSLATED")) & "images\"
myFolderName = ""
testvar1=0
testvar2=0
myPath = FolderName(Request.ServerVariables("SCRIPT_NAME") & _
                                   "?FolderPath=" & _
                                   Server.URLPathEncode(FolderPath))

%>
<html>
     <head>
          <title>ISO Documents Explorer</title>
          <LINK rel="stylesheet" type="text/css" href="Global.css">
     </head>
     <body>
<!-- Address Bar ------------------------------------------------------------->
<table width="100%" border="0">
 <tr bordercolor="#FFFFFF">
   <td width="26%"><img src="images/aalogo_r1_c1.gif" width="173" height="76"><img src="images/aalogo_r1_c2.gif"
width="61" height="78"></td>
   <td width="45%">
     <div align="center"><font size="3" color="#0033CC" face="Arial, Helvetica, sans-serif"><b><font
size="4">ISO
       Documents Index</font></b></font></div>
   </td>
   <td width="29%">&nbsp;</td>
 </tr>
</table>
<div align="center"></div>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
               
          </table>
<!-- Preperation ------------------------------------------------------------->
          <%
          'Now that the user has a way to escape if an error occurs, let's
          'create our objects.
          Set Folder = FileSystem.GetFolder(FolderPath)
          Set SubFolders = Folder.SubFolders
          Set Files = Folder.Files
          %>
<!-- Header ------------------------------------------------------------------>
          <table cellpadding="0" cellspacing="0" border="0" width="100%">
               <tr>
                    <td bgcolor="silver">Name&nbsp;</td>
                    <td bgcolor="silver" align="right">Size&nbsp;&nbsp;</td>
                    <td bgcolor="silver">Type&nbsp;</td>
                    <td bgcolor="silver">Modified&nbsp;</td>
                    <td bgcolor="silver" align="right">Attributes&nbsp;&nbsp;</td>
               </tr>
<!-- Directory Nav ----------------------------------------------------------->
               
<!-- Sub Folders ------------------------------------------------------------->
               <%
               For Each SubFolder In SubFolders
                    BgToggle
                    %>
                    <tr>
                         <td bgcolor="<%=BgColor%>" title="<%=SubFolder.Name%>">
                              <a href="<%
                              Response.Write _
                                   Request.ServerVariables("SCRIPT_NAME") & _
                                   "?FolderPath=" & _
                                   Server.URLPathEncode(FolderPath & SubFolder.Name & "\" )
                              %>"><%=Icon("_folder.gif", "Folder")%><%=SubFolder.Name%></a>
                         &nbsp;</td>
                         
                         <td bgcolor="<%=BgColor%>">&nbsp;</td>
                         <td bgcolor="<%=BgColor%>"><%=SubFolder.Type%>&nbsp;</td>
                         <td bgcolor="<%=BgColor%>"><%=SubFolder.DateLastModified%>&nbsp;</td>
                         <td bgcolor="<%=BgColor%>" align="right" class="Attributes"><%=Attributes(SubFolder.Attributes)%>&nbsp;</td>
                    </tr>
               <%Next%>
<!-- Files ------------------------------------------------------------------->
               <%
               For Each File In Files
                    BgToggle
                    Ext = FileExtension(File.Name)
                    IF Ext <> "asp" AND Ext <> "asa" AND Ext <> "css" THEN
                    %>
                    <tr>
                         <td bgcolor="<%=BgColor%>" title="<%=File.Name%>">
                         <%=Icon("ext_" & Ext & ".gif", Ext)%>
                         <a href="<%=Server.HTMLEncode(myFolderName & File.Name)%>"><%=File.Name%></a>
                         </td>
                         <td bgcolor="<%=BgColor%>" align="right"><%=Int(File.Size * .01)%>KB&nbsp;&nbsp;</td>
                         <td bgcolor="<%=BgColor%>"><%=File.Type%></td>
                         <td bgcolor="<%=BgColor%>"><%=File.DateLastModified%></td>
                         <td bgcolor="<%=BgColor%>" align="right" Class="Attributes"><%=Attributes(File.Attributes)%>&nbsp;</td>
                    </tr>
                   
               <%  END IF
               Next%>
               <%Response.Write myFolderName & "-" & "StrLength(from right) = " & testvar2 %>
<!-- End --------------------------------------------------------------------->
          </table>
          <CENTER>
               <B>
                   
               </B>
          </CENTER>
     </body>
</html>
<%
' Routines --------------------------------------------------------------------

Private Function ConvertBinary(ByVal SourceNumber, ByVal MaxValuePerIndex, ByVal MinUpperBound, ByVal
IndexSeperator)
   Dim lsResult
   Dim llTemp
   Dim giCount
   MaxValuePerIndex = MaxValuePerIndex + 1 '(1 Based Calculations)
   'Find UpperBound if Minimum Upper Bound Isn't High enough
   Do While Int(SourceNumber / (MaxValuePerIndex ^ MinUpperBound)) > (MaxValuePerIndex - 1)
       MinUpperBound = MinUpperBound + 1
   Loop
   For giCount = MinUpperBound To 0 Step -1
       'Get value of current index
       llTemp = Int(SourceNumber / (MaxValuePerIndex ^ giCount))
       'Add New Number to result
       lsResult = lsResult & CStr(llTemp)
       'Add Seperator?
       If giCount > 0 Then lsResult = lsResult & IndexSeperator
       SourceNumber = SourceNumber - (llTemp * (MaxValuePerIndex ^ giCount))
   Next
   ConvertBinary = lsResult
End Function
'------------------------------------------------------------------------------
Private Sub BgToggle()
     BackgroundColor = Not(BackgroundColor)
     If BackgroundColor Then
          BgColor = "#efefef"
     Else
          BgColor = "#ffffff"
     End If
End Sub
'------------------------------------------------------------------------------
Private Function Attributes(AttributeValue)
     Dim lvAttributes
     Dim lsResult
     lvAttributes = Split(ConvertBinary(AttributeValue, 1, 7, ","), ",")
     If lvAttributes(0) = 1 Then lsResult = "R"                    'ReadOnly?
     If lvAttributes(1) = 1 Then lsResult = lsResult & "H"     'Hidden?
     If lvAttributes(2) = 1 Then lsResult = lsResult & "S"     'System?
     If lvAttributes(5) = 1 Then lsResult = lsResult & "A"     'Archive?
     Attributes = lsResult
End Function
'------------------------------------------------------------------------------
Private Function FileExtension(FileName)
     Dim lsExt
     Dim liCount
     For liCount = Len(FileName) To 1 Step -1
          If Mid(FileName, liCount, 1) = "." Then
               lsExt = Right(FileName, Len(FileName) - liCount)
               Exit For
          End If
     Next
     If Not FileSystem.FileExists(ScriptFolder & "ext_" & lsExt & ".gif") Then
          'We don't have an icon - show the default "unknown" icon.
          lsExt = ""
     End If
     FileExtension = lsExt
End Function
'------------------------------------------------------------------------------
Private Function ParseFolder(PathString)
     Dim liCount
     If Right(PathString, 1) = "\" Then
          ParseFolder = PathString
     Else
          For liCount = Len(PathString) To 1 Step -1
               If Mid(PathString, liCount, 1) = "\" Then
                    ParseFolder = Left(PathString, liCount)
                    Exit For
               End If
          Next
     End If
End Function
'------------------------------------------------------------------------------
Private Function Icon(Src, Alt)
     Icon = _
          "<img src=""images/" & Src & """ alt=""" & Alt & """" & _
          " width=""16"" height=""16"" border=""0"">"
End Function
'------------------------------------------------------------------------------
Private Function FolderName(UrlString)
 Dim strCount
 Dim pCount
 Dim EndPoint
 Dim BegPoint
 Dim strLength
 
 pCount = 0
 BegPoint = 0
 EndPoint = 0
 strLength = 0
 
 For strCount = Len(UrlString) To 1 Step -1
   If Mid(UrlString, strCount, 3) = "%5C" Then
     'ending string terminator found ... keep going
     EndPoint = strCount
     For pCount = (EndPoint - 1) To 1 Step -1
       If Mid(UrlString, pCount, 3) = "%5C" Then
         BegPoint = pCount - 2
         Exit For
       End If
     Next

      strLength = BegPoint - 2
      testvar2 = strLength
      myFolderName = Right(UrlString, strLength)
   End If
 Next
 
 
End Function


%>
0
Comment
Question by:dwadek
2 Comments
 
LVL 2

Accepted Solution

by:
sbmc earned 100 total points
ID: 6448294
You aren't exiting the outer For loop so its processing the whole URLString each time. Try this

Private Function FolderName(UrlString)
Dim strCount
Dim pCount
Dim EndPoint
Dim BegPoint
Dim strLength
Dim Found

pCount = 0
BegPoint = 0
EndPoint = 0
strLength = 0
Found=False

For strCount = Len(UrlString) To 1 Step -1
  If Mid(UrlString, strCount, 3) = "%5C" Then
    'ending string terminator found ... keep going

    EndPoint = strCount
    For pCount = (EndPoint - 1) To 1 Step -1
      If Mid(UrlString, pCount, 3) = "%5C" Then
        BegPoint = pCount - 2
        Found=True
        Exit For
      End If
    Next

     strLength = BegPoint - 2
     myFolderName = Right(UrlString, strLength)
     testvar2 = strLength & " (" & myfoldername & ")"
      if Found then exit for

  End If
Next


End Function
0
 

Author Comment

by:dwadek
ID: 6453854
Thanks for your help
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Highlight a word from some text 16 56
Select distinct 25 101
Generate report pulling data (links) from three tables 31 65
Hide cell in a table 2 14
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

809 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