listing folder and file contents

Discussion in 'C#' started by aqutan, Oct 30, 2007.

  1. #1
    i have code below which lists folders and the contents of that folder in a javascript div box to the right. When i select the folder the list of files appear, when i select another folder the list of the previous folder selected still appears with the new list shown over the top of it. I need to know how i can make the list automatically disappear each time i select a new folder or is there a better way of doing this? Thanks in advance

    Code:

    <%
    folderpath = server.mappath("/example/files")

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set fold = fso.GetFolder(folderpath)

    for each subfolder in fold.subFolders

    Response.Write("<a href=""javascript:;"" onmousedown=""toggleDiv('"& subfolder.Name &"');"" class=""leftbox"">" & subfolder.Name & "</a><br>")
    dim divid
    divid = subfolder.Name
    Response.Write"<br>"
    Response.Write "</p>"

    Response.Write "<DIV class=""rightbox"" id='" & divid & "' style=""display:none"">" '<!--style="display:none"-->


    'response.Write "sGroupName = " & sGroupName & "<br>"
    Dim dirName
    sGroupName = divid
    dirName = "/example/files/" & sGroupName & "/"
    'response.Write dirName
    Dim oFS, oFolder, oFile, oFiles, nCount, arr
    Set oFS = CreateObject("Scripting.FileSystemObject")
    Set oFolder = oFS.GetFolder(server.MapPath(dirName))
    'response.write "oFolder = " & oFolder
    Set oFile = oFolder.Files
    ReDim arr(oFile.Count - 1)
    i = 0
    For Each aFile In oFile
    'Response.Write "i= " & i
    Set arr(i) = aFile
    i = i + 1
    Next
    Response.Write("<a href=""javascript:;"" onmousedown=""toggleDiv('"& subfolder.Name &"');"" class=""contentText"">Close </a><br>")
    For i = 0 To UBound(arr)

    Response.Write "<a class=""contentText"" href=""" & sGroupName & "/" & arr(i).Name & """>" & left(arr(i).Name,len(arr(i).Name)-4) &"</a><br>"
    next
    Response.Write "</p> </div>"
    next

    set fold = nothing
    set fso = nothing
    %>
     
    aqutan, Oct 30, 2007 IP
  2. BuildHome

    BuildHome Well-Known Member

    Messages:
    837
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    108
    #2
    Please show us all the JS code so we can help you out :)
     
    BuildHome, Nov 2, 2007 IP
  3. teraeon

    teraeon Peon

    Messages:
    40
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Your function should look like the following:


    var PreviousFolder;

    function toggleDiv( sFolder ){
    var oFolder;
    if( PreviousFolder != null ){
    oFolder = document.getElementById(PreviousFolder);
    oFolder.style.display = "none";
    }
    oFolder = document.getElementByID(sFolder);
    oFolder.style.display = "block";
    PreviousFolder = sFolder;

    }
     
    teraeon, Nov 4, 2007 IP