[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 670
  • Last Modified:

How to automatically create hyperlinks to files and folders in html page??

i have a handful of users that upload documents to a server and i want to have hyperlinks created to these documents after they are uploaded or a form that does it all.  is this possible??  i am using asp and html.
0
amoos
Asked:
amoos
  • 6
  • 6
1 Solution
 
rbudjCommented:
The logic would be to create a page that pulls a string from a database table.

The user would upload a document called something like: myDocument.doc.  Along with the code you are using to place the document on the server, have it create a string in a data field called something like url.  

On your page, you simply create a for loop to display as a link for each row in the table.

0
 
b0lsc0ttCommented:
amoos,

You don't even need a database.  Are these documents in a web accessible folder?  Can you put an ASP page in that folder or another?  You can use the FileSystemObject to look at the uploaded documents and make a page with links.  Of course this assumes they are easily identifiable in some way (i.e. only ones in the directory or have a similar name/extension).  If the uploaded files are mixed with others and could be any name and type then you will need what was recommended above.

Let me know if you have any questions or need more information.  I will provide a basic sample of using the FSO object like this but can help you adapt it if you have a question or problem.

b0lsc0tt
0
 
b0lsc0ttCommented:
amoos,

An example of using that object and code to show the file and it's path is below.  It should be easy to modify as you want to show the info and make a link.

Let me know if you have a question.

b0lsc0tt
Dim strFileSize 
Set MyDirectory=Server.CreateObject("Scripting.FileSystemObject")
Set MyFiles=MyDirectory.GetFolder(Server.MapPath("/misc/"))
For each filefound in MyFiles.files
	If filefound.Name <> "default.asp" then
	If Len(filefound.Size) > 6 then
		strFileSize = Round(CSng(filefound.Size) / 1000000, 2) & " MB"
	Elseif Len(filefound.Size) > 3 then
		strFileSize = CStr(Round(CSng(filefound.Size) / 1000, 2)) & " KB"
	Else
		strFileSize = filefound.Size & " B"
	End if %>
	<tr>
		<td align="left">&nbsp;&nbsp;&nbsp;<%= filefound.Name %></td>
		<td align="center"><%= FormatDateTime(filefound.DateLastModified,2) %></td>
		<td align="center"><%= strFileSize %></td>
		<td align="left">http://www.yourdomain.com/misc/<%= filefound.Name %></td>
	</tr>
	<%
	End if
Next

Open in new window

0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
amoosAuthor Commented:
awesome script thank you.  so where in my web page can i put this code in??  can i make a blank html page and then copy and paste yhr code above into it to test it??  awesome script thank you
0
 
b0lsc0ttCommented:
The use would be up to you.  That code was used in a page called default.asp.  The file was in the same folder as uploaded files.  All the other files in that folder are listed (line 5 in that code prevents it from listing itself).  There was more html to make a table and show everything nice but that is the key ASP part.  The page needs to be an ASP page; an html page won't be able to run the ASP code and isn't dynamic.
If you want the list in an existing page then you could just add that code to the appropriate section, put the code in a function and call it, or whatever.  Some modification to the html made will probably be needed to fit your page but should be minor.
If you need specifics on using it then let me know details about how and what code you have.  I'm glad it helped.  There are lots of good spots online with info on that object and other examples of using it but http://www.w3schools.com/asp/asp_ref_filesystem.asp is a pretty good reference and start for general info.
bol
0
 
amoosAuthor Commented:
awesome.  so if i save the above code as default.asp in the directory where the uploaded files are will it create links to those documents on a new page or on a page that already exsists?? would i have to manually run this asp script or add it into another asp script or my uploader script so that when a new document is uploaded it makes a link on a page for the new document??

basically what i am trying to accomplish is i have a directory that has lots of pdf's in it and i would really like to have a search on the page that someone can type in let;s say document one and it finds the document and opens it up for the user to see.  is this possible???

if not then what i would like to accomplish is that everytime someone uploads a document to the directory on the server it makes a hyperlink to that document in a new page.

i know i am asking too much or i am just confused and it is simplar than i think.

awesome help thank you so much
0
 
b0lsc0ttCommented:
>> so if i save the above code as default.asp in the directory where the uploaded files are will it create links to those documents on a new page or on a page that already exsists?? <<
Remember that page makes code for a table so you either need to change the html that is made or put that code in a page that will start with the proper html and then end the table.  That code is also made to run in a folder called "misc" that is on the root of your site (e.g.  http://yourdomain/misc/default.asp).  Line 3 is the one that would need to be changed if your folder is named different or somewhere else.
The page when run will show the contents of that folder (except itself).  Those files are listed on default.asp and the list includes all files in the folder.  It is automatically updated as you add files and so will always print the latest files.  You will need to make some modification to the html to have it make a link but that should be really easy.
I hope this answers your second question too but let me know if not.
>> [search] is this possible??? <<
Not with the code I provided and it would be a whole new question.  It is more complicated.
>> it makes a hyperlink to that document in a new page.<<
Why a new page?  What page?  This is now becoming a different question from what your originally asked.
Do you know ASP at all?  Can you use an ASP file on your web server?  Have you tried to my code to see what it does and produces?  If not start there.  I did adapt the code I provided so it would just make a link for each file.  See the code below.  That code could be run as its own page (after adding starting and ending html).  If you have a question about what you get or need something different then please let us know.  Keep in mind what you asked here though.  It won't provide a way to search and doesn't do something for making a new page for each file.
bol

<%
Dim strFileSize 
Set MyDirectory=Server.CreateObject("Scripting.FileSystemObject")
Set MyFiles=MyDirectory.GetFolder(Server.MapPath("/misc/"))
For each filefound in MyFiles.files
	If filefound.Name <> "default.asp" then
%>
		<a href="/misc/<%= filefound.Name %>"><%= filefound.Name %></a><br />
	<%
	End if
Next
%>

Open in new window

0
 
amoosAuthor Commented:
sorry for any confusion that i have given you.  i used the code that you gave to me above and i pasted it below.  i created a misc folder as specified and there are two documents in this misc folder.  i am learning asp but i am not an expert at it.  yes we can run asp pages on our web server.  everything that you have posted has really helped me learn and i thank you very much for that.  from the code below what is next for me to test it to see the results??  thank you so much for all your help you are awesome.

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<%
Dim strFileSize
Set MyDirectory=Server.CreateObject("Scripting.FileSystemObject")
Set MyFiles=MyDirectory.GetFolder(Server.MapPath("/misc/"))
For each filefound in MyFiles.files
      If filefound.Name <> "default.asp" then
%>
            <a href="/misc/<%= filefound.Name %>"><%= filefound.Name %></a><br />
      <%
      End if
Next
%>
</body>
</html>
0
 
amoosAuthor Commented:
sorry for the last post i tested it and it is brillant and what i needed.  thank you so much sorry for the confusion.  thank you for your help and your patience.  

i did have one last question though, since i have tons of pdf's in this directory then is there anyway to get the results displayed by the asp script you wrote to alphabetize the documents??  or am i asking too much??

awesome help thank you so much
0
 
b0lsc0ttCommented:
I am glad it worked and has provided what you wanted.  The way you used it looks fine and I noticed from your second post it worked.
 >> is there anyway to get the results displayed by the asp script you wrote to alphabetize the documents?? <<
It involves a little more code but it can be sorted.  There is no way to do it just with the FSO object though and that is why more code.  The method I use is to make a new, temporary recordset object, store the info in it, and then sort that object.  Works great and isn't too much more work.  If you need details or help doing it then open a new question for it.  I will include 2 previous questions on this I have participated in though so that may be all you need.
http:/Q_21917232.html
http:/Q_21969876.html
If you do open a new question for this and would like my attention to it then feel free to post a comment here with the new question's URL.
bol
0
 
amoosAuthor Commented:
thank you so much.  i am going to accept an answer so you get the points and i did post another question like you asked and the link is below.  thanks again for all your help


http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/HTML/Q_24154601.html
0
 
amoosAuthor Commented:
awesome help, truely awesome
0
 
b0lsc0ttCommented:
Your welcome!  I'm glad I could help.  Thanks for the grade, the points and the fun question.
bol
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now