Link to home
Start Free TrialLog in
Avatar of jsvb1977
jsvb1977

asked on

How to make PDF file list in directory clickable links

I have created a directory on the c drive of our web server where users on our local network will drop PDF files.

I have written a routine in asp.net [vb] that iterates through the files in that directory and builds a bulleted list with href links based on the file name and path.

Problem is, the href renders the files with links like this:
file:///C:/GrapevinePDFs/gv_1017.pdf

This is not a valid url or clickable link.

How do turn the file path shown above into a clickable link that visitors to the website can click on to view the PDFs?

Here is the code:

        Dim strGrapeVineHREF As String
        Dim strGrapeVineLink As String
        Dim strPath As String = "C:\GrapevinePDFs"
        For Each strGrapeVineHREF In System.IO.Directory.GetFiles(strPath, "*.pdf")

            strGrapeVineLink = GrapeVineVerboseName(strPath, strGrapeVineHREF)
            Dim li As New HtmlGenericControl("li")
            li.InnerHtml = "<a href=""" & strGrapeVineHREF & """ title=""View Grapevine Article"" target=""_blank"">" & strGrapeVineLink & "</a>"
            bulGrapevineArticles.Controls.Add(li)

        Next

Open in new window


Avatar of jsvb1977
jsvb1977

ASKER

oh yeah, here is the rendered HTML that the routine above spits out:

<ul id="ctl00_cpMainContent_bulGrapevineArticles" class="grapevinelist">
<li><a href="C:\GrapevinePDFs\gv_1017.pdf" title="View Grapevine Article" target="_blank">Volume 10 - Issue 17</a></li>
<li><a href="C:\GrapevinePDFs\gv_1018.pdf" title="View Grapevine Article" target="_blank">Volume 10 - Issue 18</a></li>
<li><a href="C:\GrapevinePDFs\gv_1019.pdf" title="View Grapevine Article" target="_blank">Volume 10 - Issue 19</a></li></ul>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of HainKurt
HainKurt
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Here is the entire block of code:
The Virtual Directory was the real solution, though...


        Dim strGrapeVine As String
        Dim strGrapeVineHREF As String
        Dim strGrapeVineLink As String
        Dim strPath As String = "C:\GrapevinePDFs\"
        For Each strGrapeVine In System.IO.Directory.GetFiles(strPath, "*.pdf")

            strGrapeVineHREF = strGrapeVine.Replace(strPath, "GrapevinePDFs/")
            strGrapeVineLink = GrapeVineVerboseName(strPath, strGrapeVine)
            Dim li As New HtmlGenericControl("li")
            li.InnerHtml = "<a href=""" & strGrapeVineHREF & """ title=""View Grapevine Article"" target=""_blank"">" & strGrapeVineLink & "</a>"
            bulGrapevineArticles.Controls.Add(li)

        Next

Open in new window

I did not write the code since I thought you could do it ;)
Hainkurt,

I could see how my last post could have been construed as negative, but it was intended to give you praise.

I only posted the code I wrote so the next person might find it useful.

Thanks for everything!
Jason