Solved

ASP Text Parsing Routines/Variables Not Refreshing?

Posted on 2001-09-01
2
253 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

930 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now