Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Dynamic alphabet links asp/vb

twarden1twarden1 Member Posts: 2
What little asp I've learned, I've learned on the fly, editing existing code. So I don't know what an "object" is, etc. Now that you know what level I'm on, here's my problem:

I need an alphabet list at the top of a page that dynamically creates a link if data exists under that letter. My data is NOT coming from a database. Basically, I'm listing all the filenames of documents in a folder and making them links to open those documents. I've got the list of documents working just fine, as well as the links to those documents. I'm struggling with how to word this, so bear with me. Here's what I need. Let's say I have the following documents in a folder:

aa1234.doc
ee1234.doc
uu1234.doc
zz1234.doc

I currently have a page that displays these doc names and links them to their respective documents. In this case, my alphabet should look like:

[u][color=Blue]a[/color][/u] | b | c | d | [u][color=Blue]e[/color][/u] | f.... | [u][color=Blue]u[/color][/u] | v | w | x | y | [u][color=Blue]z[/color][/u]

Naturally each link would open my existing page, but filtering out all filenames except the one selected.

Here's the code I currently have for displaying these filenames so you my file locations and variable names (there's a lot of [color=Green]documentation[/color] mixed in from previous code, I just don't understand it all - sigh).

<%
[color=Green]'Begin code to dynamically view documents in directory.[/color]
Server.ScriptTimeout = 3600
iFileCount = 0

[color=Green]'Create the Scripting File System Object & set variable for the folder that contains the documents we want.[/color] Set strDirectory = Server.CreateObject("Scripting.FileSystemObject")
Set strDocs = strDirectory.GetFolder(strDocPathNov)

[color=Green]'Check to see if folder exists. If it does then continue.[/color]
sFolderName = strDocs.name
If UCase(sFolderName) = "NOVATION" Then

[color=Green]'Check to see if any files exist. If at least one does then continue.[/color]
sFolderSize = strDocs.size
If sFolderSize > 1000 Then

[color=Green]'Use response.write statements below to create HTML that outputs the filenames in an unordered list.[/color]

response.write "
    "

    [color=Green]'Get the list of documents using a For...Next Loop
    'For every file found in the folder...[/color]
    For each strFileFound in strDocs.files

    [color=Green]'Check to see if the file is a PDF by looking at the extension. Use UCASE function to include both .pdf & .PDF extensions.[/color]
    If UCase(Right(strFileFound.Name,4)) = ".PDF" Then
    [color=Green]'If the file is a PDF output it to the page; otherwise, ignore it.[/color]
    response.write "
  • "
    [color=Green]'The anchor tag below will contain the complete path and filename, but the screen will only list the filename without the extension.
    'The NewStr function replaces underscores in the display name with spaces for easier readability.[/color] response.write "" & NewStr(Left(strFileFound.Name,Len(strFileFound.Name)-4)) & ""
    response.write "
  • "
    [color=Green]'Increment file counter.[/color] iFileCount = iFileCount + 1
    End If
    Next %>
    (I use the filecount in a different spot and everything is closed at the bottom of the code)

    Here's some code I found that displays alphabet links at the top, but they don't do anything yet. I'd like to build on this.

    <% sAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" %>
    <%
    For z = 1 to 26
    char = Mid(sAlphabet,Z,1)
    Response.Write "<a href=default.asp?id=" & char & ">" & char & " | "
    next
    %>
     ALL

    All existing variabled have been declared.

    Please help... I have precious little time on this and sad to say, I'm a sucky "programmer." =`(

Comments

  • twarden1twarden1 Member Posts: 2
    : What little asp I've learned, I've learned on the fly, editing
    : existing code. So I don't know what an "object" is, etc. Now that
    : you know what level I'm on, here's my problem:
    :
    : I need an alphabet list at the top of a page that dynamically
    : creates a link if data exists under that letter. My data is NOT
    : coming from a database. Basically, I'm listing all the filenames of
    : documents in a folder and making them links to open those documents.
    : I've got the list of documents working just fine, as well as the
    : links to those documents. I'm struggling with how to word this, so
    : bear with me. Here's what I need. Let's say I have the following
    : documents in a folder:
    :
    : aa1234.doc
    : ee1234.doc
    : uu1234.doc
    : zz1234.doc
    :
    : I currently have a page that displays these doc names and links them
    : to their respective documents. In this case, my alphabet should look
    : like:
    :
    : [u][color=Blue]a[/color][/u] | b | c | d |
    : [u][color=Blue]e[/color][/u] | f.... | [u][color=Blue]u[/color][/u]
    : | v | w | x | y | [u][color=Blue]z[/color][/u]
    :
    : Naturally each link would open my existing page, but filtering out
    : all filenames except the one selected.
    :
    : Here's the code I currently have for displaying these filenames so
    : you my file locations and variable names (there's a lot of
    : [color=Green]documentation[/color] mixed in from previous code, I
    : just don't understand it all - sigh).
    :
    : <%
    : [color=Green]'Begin code to dynamically view documents in
    : directory.[/color]
    : Server.ScriptTimeout = 3600
    : iFileCount = 0
    :
    : [color=Green]'Create the Scripting File System Object & set
    : variable for the folder that contains the documents we want.[/color]
    : Set strDirectory =
    : Server.CreateObject("Scripting.FileSystemObject")
    : Set strDocs = strDirectory.GetFolder(strDocPathNov)
    :
    : [color=Green]'Check to see if folder exists. If it does then
    : continue.[/color]
    : sFolderName = strDocs.name
    : If UCase(sFolderName) = "NOVATION" Then
    :
    : [color=Green]'Check to see if any files exist. If at least one
    : does then continue.[/color]
    : sFolderSize = strDocs.size
    : If sFolderSize > 1000 Then
    :
    : [color=Green]'Use response.write statements below to create
    : HTML that outputs the filenames in an unordered list.[/color]
    :
    : response.write "
      "
      :
      : [color=Green]'Get the list of documents using a For...Next Loop
      : 'For every file found in the folder...[/color]
      : For each strFileFound in strDocs.files
      :
      : [color=Green]'Check to see if the file is a PDF by looking
      : at the extension. Use UCASE function to include both .pdf & .PDF
      : extensions.[/color]
      : If UCase(Right(strFileFound.Name,4)) = ".PDF" Then
      : [color=Green]'If the file is a PDF output it to the page;
      : otherwise, ignore it.[/color]
      : response.write "
    • "
      : [color=Green]'The anchor tag below will contain the
      : complete path and filename, but the screen will only list the
      : filename without the extension.
      : 'The NewStr function replaces underscores in the display
      : name with spaces for easier readability.[/color]
      : response.write "" &
      : NewStr(Left(strFileFound.Name,Len(strFileFound.Name)-4)) & "
      "
      : response.write "
    • "
      : [color=Green]'Increment file counter.[/color] iFileCount =
      : iFileCount + 1
      : End If
      : Next %>
      : (I use the filecount in a different spot and everything is closed at
      : the bottom of the code)
      :
      : Here's some code I found that displays alphabet links at the top,
      : but they don't do anything yet. I'd like to build on this.
      :
      : <% sAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" %>
      : <%
      : For z = 1 to 26
      : char = Mid(sAlphabet,Z,1)
      : Response.Write "<a href=default.asp?id=" & char & ">" & char & "
      : | "
      : next
      : %>
      :  ALL
      :
      : All existing variabled have been declared.
      :
      : Please help... I have precious little time on this and sad to say,
      : I'm a sucky "programmer." =`(
      :
      Thought I'd go ahead and include the declarations and path to the documents:
      <% 'Declare variables including ones that are pulled in by include files.
      Dim strPageName, url, strCheckUrl, strPathNov, strDocPathNov, strFolder, strDirectory, strDocs, strFileFound, sAlphabet, z, char
      Dim sFolderName, sFolderSize, iFileCount

      'Set server paths
      strPathNov = "/legaldocs/secure/novation"

      'This variable will be used by the Scripting File System Object.
      strDocPathNov = "d:inetpubwwwrootvhasecurenetlegaldocssecure
      ovation"

      'This function replaces an underscore character with a space.
      Function NewStr(str)
      NewStr = Replace(str, "_", " ")
      End Function
      %>

Sign In or Register to comment.