?
Solved

ASP Text Parsing Routines/Variables Not Refreshing?

Posted on 2001-09-01
2
Medium Priority
?
261 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
[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
2 Comments
 
LVL 2

Accepted Solution

by:
sbmc earned 400 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

764 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