PDA

View Full Version : adding browse for directory for my current script


flyclassic
11-19-2002, 04:27 AM
Hi, I've this current script(ASP) that need modification which i've stucked.
My current script work this way, whenever my webpage starts it will go into a specific folder and search for extention ".xml" files and will list them out in a drop down list.

<%


Private Function getFilesByType(strFolder, strType)
'getFilesByType
' returns an Array of files for a specific type in a folder
' if no files where found returns null
Dim objFSO, objFolder, fileItem, fileCollection, arrFiles, i
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strFolder)
Set fileCollection = objFolder.Files
response.write("<select name=""xmlfileid"" onclick=""showpreview_brief(selection.xmlfileid.value)"">")

i = 0
For Each fileItem in fileCollection
If (lCase(Right(fileItem.name, len(fileItem.name) - InStr(fileItem.name, "."))) = lCase(strType)) Then
If (i <> 0) Then
arrFiles = arrFiles & ";"
End If
i = i + 1
response.write("<option value=""xmldata/" &fileItem.name &""">" &fileItem.name)




'arrFiles = arrFiles & fileItem.name

End If
Next
Set objFSO = Nothing
Set objFolder = Nothing
Set fileCollection = Nothing
If (isNull(arrFiles) Or arrFiles = "") Then
getFilesByType = Null
Else
getFilesByType = Split(arrFiles, ";")
End If
response.write("</select>")

End Function


getFilesByType server.mappath("/MyProj/xmldata"), "xml"

%>



However, i wanted to add another drop down list beside to allow user to select a specfic web server directory (for exame /MyProj/A/xmldata/ , /MyProj/B/xmldata/)
before it will display the xml drop down list with a list of the xml files. Meaning, user can select a directory from a drop down list and it wil automatically create another drop down list listing their xml files, in other words dynamic. I'm very confused as how to implement it into my current script. Can anybody help me solve?

Mhtml
11-19-2002, 04:48 AM
When calling the function just have the strFolder variable you are sending be the value the form that was submitted, it would be a good idea to have conditions for sending it that way so that you don't get errors.

eg;

if Request.Form("UserDirectory") > 0 Then
GetFilesByType(Request.Form("UserDirectory"), "Xml")
End if


You can stick a else statement in there to make it bette.

whammy
11-23-2002, 12:19 AM
Are you trying to do this without refreshing the page? If so, that's more of a javascript question.

If you don't mind refreshing the page, then just send the variable retrieved from your first select dropdown to the page again, and then populate your second dropdown based on the first dropdown's value. You need to figure out how to do that first anyway, if you intend on converting the process to client-side, since you will have to prepopulate all possible arrays, I think...

I believe ASP.NET can do this rather easily (if I'm not mistaken), but unfortunately I'm still a total newbie at it for the moment...

Mhtml
11-23-2002, 05:04 AM
Or you could store each entry in a js array which you can create by looping through the files and then if the users wishes to have the dropdown populated with different and or more values it can just call these from the array.

Have a think about it.