...

View Full Version : What's the best way to...



anessa05
04-05-2007, 11:38 PM
Hi! I have over 1,000 pdf files. They are currently divided up into folders for branch/camp/month and year. There are 4 branches, 168 camps, and monthly pdf files dating all the way back to 2001. What would be the best way to allow visitors to go to a web page, select and download specific pdf files? The website is built in ASP.

Daemonspyre
04-06-2007, 01:19 PM
I am not sure that there is a truly "EASY" way to do this, but I know of 2 different approaches (there may be more...).

1) Create a database for the pdf files. PDF Name, FileLocation, FileName would be 3 of the [at least 5] fields that I would choose.

Now, with 4 branches, 168 camps, monthly PDF files for 6 years, that would take a while, but you could update it and use an UPLOAD tool to post any new files to these folders.

2) Use the Scripting.FileSystemObject method in ASP. With this method, you could navigate to a folder (using code), read the files in the folder, download them accordingly, navigate to another folder, etc.

With this method, you could also automatically insert records into above said database and have the computer do the grunt work for you.

Need some extra help on this? Let me know...

anessa05
04-06-2007, 02:21 PM
Thank you for your suggestions. Option 2) Use the Scripting.FileSystemObject method in ASP, sounds like the way to go. However, I haven't used it before and couldn't find anything online explaining how to use it to retrieve non txt files dynamically via a form. Could you direct me to some examples and a tutorial on how I could use it to retrieve the pdfs please?

Daemonspyre
04-06-2007, 03:05 PM
First place to start looking is the MSDN:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/af4423b2-4ee8-41d6-a704-49926cd4d2e8.asp


Second place to start is this example code:


<ol id="pdfFiles">

<%
Set fso = CreateObject("Scripting.FileSystemObject")
'
locale = Server.MapPath("/path/to/files") ' please note that this can be a variable.
'
locShort = "/path/to/files" ' this needs to be the same location as above. See below for why.
'
Set folder = fso.GetFolder(locale)
'
for each fl in folder.files
response.write(chr(9) & "<li><a target=""_blank"" href=""" & locShort & fl.Name & """>" & fl.Name & "</a></li>" & vbCrLf)
next
'
Set folder = nothing
Set fso = nothing
' destroy variables when done. This is clean up.
%>

</ol>


As a side note, chr(9) is the TAB character, vbCrLf is "visual basic Carriage Return Line Feed". I like my "VIEW SOURCE" to look as nice as my HTML. These are not needed and are only for showing my 'Monkish' OCD nature. :)

So let's say that you have a directory structure /Camp1/April/.

Scripting.FileSystemObject (FSO) will look in that folder at every file. It will then read the contents and list them out. Since I have made these HREF links, browsers will see the link as:


<li><a target="_blank" href="/Camp1/April/file1.pdf">File 1.pdf</a></li>

You can, of course, change this around to suit your needs. You can specify which files you want (or don't want) to see, use streaming to push them all into 1 Zip file, etc.

HTH, and let me know if you have any more questions.

degsy
04-18-2007, 02:38 PM
You can setup a recursive folder output

here is an example
http://www.brainjar.com/asp/dirlist/

You can then format the results to create HTML links to download the files, or use a download manager
http://forums.aspfree.com/code-bank-54/download-manager-downloading-files-from-secure-location-classic-asp-65239.html

anessa05
05-06-2007, 06:43 PM
Thanks Daemonspyre! Instead of listing the pdf files in an ordered list, I'd like them in a drop down, so the user can then select the one they want and immediately download it. How can I do that? Below is page one of the current method used to allow the user to select a pdf to download. It works okay. However, I have to hard code the monthly updates to 8 pages each month and the dropdown always show duplicate listings. Hence why I'm looking for a better/easier method.

In the next posting is the 'action' page code [f2.htm].


<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
<base target="main">

</head>

<body background="../../Background_Tiles/Mar10thOffwhiteBkgrndTile.jpg" leftmargin="20">
<center><img border="0" src="../injurybanner.gif" width="471" height="60"></center>

<script language="javascript">
document.write("<FORM METHOD=LINK ACTION=F2.htm>");
document.write("<p align=center><table width=339 align=center><tr><td width=132 align=left>");
document.write("<p align=left>Choose a Location:</p></td><td width=196 align=left>");
document.write("<select name=CAMP onChange =submit() >");
document.write("<option value=army>Army All<option value=aberdeen>Aberdeen Prov. Ground <option value=belvoir>Fort Belvoir <option value=benning>Fort Benning<option value=bliss>Fort Bliss<option value=bragg>Fort Bragg<option value=campbell>Fort Campbell");
document.write("<option value=carson>Fort Carson<option value=drum>Fort Drum<option value=eustis>Fort Eustis<option value=gordon>Fort Gordon<option value=hood>Fort Hood<option value=huachuca>Fort Huachuca<option value=irwin>Fort Irwin");
document.write("<option value=jackson>Fort Jackson<option value=knox>Fort Knox<option value=leavenworth>Fort Leavenworth<option value=lee>Fort Lee<option value=wood>Fort Leonard Wood<option value=lewis>Fort Lewis<option value=meade>Fort Meade");
document.write("<option value=polk>Fort Polk<option value=riley>Fort Riley<option value=rucker>Fort Rucker<option value=samhouston>Fort Sam Houston<option value=sill>Fort Sill<option value=stewart>Fort Stewart<option value=story>Fort Story<option value=wainwright>Fort Wainwright");
document.write("<option value=europe>Europe<option value=hawaii>Hawaii<option value=hunter>Hunter AAF<option value=korea>Korea<option value=westpoint>USMA West Point<option value=washington>Washington DC </select>");

document.write("</td></tr><tr><td width=132 align=left> <p align=left>Choose a Report:&nbsp &nbsp</td><td width=196 align=left>");
document.write("<select name=MONTH onChange=submit()><option value=April07>April 2007<option value=March07>March 2007<option value=February07>February 2007<option value=January07>January 2007<option value=December06>December 2006<option value=November06>November 2006<option value=October06>October 2006<option value=September06>September 2006<option value=August06>August 2006<option value=July06>July 2006<option value=June06>June 2006<option value=May06>May 2006<option value=April06>April 2006<option value=March06>March 2006<option value=February06>February 2006<option value=January06>January 2006<option value=December05>December 2005<option value=November05>November 2005<option value=October05>October 2005<option value=September05>September 2005<option value=August05>August 2005<option value=July05>July 2005<option value=June05>June 2005<option value=May05>May 2005<option value=April05>April 2005<option value=March05>March 2005<option value=February05>February 2005<option value=January05>January 2005<option value=December04>December 2004<option value=November04>November 2004<option value=October04>October 2004<option value=September04>September 2004<option value=August04>August 2004<option value=July04>July 2004<option value=June04>June 2004<option value=May04>May 2004<option value=April04>April 2004<option value=March04>March 2004<option value=February04>February 2004<option value=January04>January 2004<option value=December03>December 2003<option value=November03>November 2003<option value=October03>October 2003<option value=September03>September 2003 <option value=August03>August 2003<option value=July03>July 2003<option value=June03>June 2003<option value=May03>May 2003<option value=April03>April 2003<option value=March03>March 2003<option value=February03>February 2003<option value=January03>January 2003<option value=December02>December 2002<option value=November02>November 2002<option value=October02>October 2002<option value=September02>September 2002<option value=August02>August 2002<option value=July02>July 2002<option value=June02>June 2002<option value=May02>May 2002<option value=April02>April 2002<option value=March02>March 2002<option value=February02>February 2002<option value=January02>January 2002 <option value=December01>December 2001<option value=November01>November 2001<option value=October01>October 2001 </select>");

document.write("</td></tr></table>");
document.write("</Form>");

camp = "army";
month = "April07";

document.write("<center><td width=517><table border=0 cellpadding=12><tr>");
document.write(" <td align=center><strong><font size=2>");
document.write(" <a href="+ camp +"/"+ month +"/"+ camp +"1.pdf target=_top>Injury Trends </a></font></strong></td>");
document.write(" <td align=center><strong><font size=2><a href="+ camp +"/"+ month +"/"+ camp +"2.pdf target=_top>Causes of<br>");
document.write(" Serious Injury</a></font></strong></td>");
document.write("<td align=center><strong><font size=2><a href="+ camp +"/"+ month +"/"+ camp +"3.pdf target=_top>Medical<br>");
document.write(" Encounters</a></font></strong></td>");
document.write("<td align=center><strong><font size=2><a href="+ camp +"/"+ month +"/"+ camp +"4.pdf target=_top>Soldier<br>");
document.write(" Duty Status</a></font></strong></td>");
document.write("<td align=center><strong><font size=2><a href="+ camp +"/"+ month +"/"+ camp +".pdf target=_top>View<br>");
document.write("Entire Report</a></font></strong></td>");
document.write("</tr>");
document.write("<tr>");
document.write("<td align=center><strong><a href="+ camp +"/"+ month +"/"+ camp +"1.pdf target=_top><img border=0 src=../injurytrends.gif width=77 height=97></a></strong></td>");
document.write("<td align=center>");
document.write(" <p align=center><strong><a href="+ camp +"/"+ month +"/"+ camp +"2.pdf target=_top><img border=0 src=../causes.gif width=74 height=97></a></strong></td>");
document.write("<td align=center>");
document.write(" <p align=center><strong><a href="+ camp +"/"+ month +"/"+ camp +"3.pdf target=_top><img border=0 src=../medical.gif width=73 height=97></a></strong></td>");
document.write(" <td align=center><strong><a href="+ camp +"/"+ month +"/"+ camp +"4.pdf target=_top><img border=0 src=../last.gif width=75 height=97></a></strong></td>");
document.write(" <td align=center><strong><a href="+ camp +"/"+ month +"/"+ camp +".pdf target=_top><img border=0 src=../Front.gif width=74 height=97></a></strong></td>");
document.write("</tr></table><p align=center>&nbsp<p align=center>&nbsp</div></center><p align=center>&nbsp</p>");
document.write("</form>");
</script>

</body>
</html>

anessa05
05-06-2007, 06:45 PM
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>


</head><body background="../../Background_Tiles/Mar10thOffwhiteBkgrndTile.jpg" leftmargin="20">


<FORM NAME="form1">
<INPUT TYPE="hidden" NAME="input1" SIZE="35">
</FORM>

<SCRIPT LANGUAGE="javascript">

var locate = window.location
document.form1.input1.value = locate

var text = document.form1.input1.value

function delineate(str){

theleft = str.indexOf("=") + 1;
theright = str.lastIndexOf("&");
return(str.substring(theleft, theright));
}
</SCRIPT>

<SCRIPT LANGUAGE="javascript">

var locate = window.location
document.form1.input1.value = locate

var text = document.form1.input1.value

function delineate2(str){

point = str.lastIndexOf("=");

return(str.substring(point+1,str.length));
}
</SCRIPT>

<script language="javascript">

camp=delineate(text);

month=delineate2(text);

switch(camp){
case "army":
PROPER1="Army All";
break;
case "aberdeen":
PROPER1="Aberdeen Prov. Ground";
break;
case "belvoir":
PROPER1="Fort Belvoir";
break;
case "benning":
PROPER1="Fort Benning";
break;
case "bliss":
PROPER1="Fort Bliss";
break;
case "bragg":
PROPER1="Fort Bragg";
break;
case "campbell":
PROPER1="Fort Campbell";
break;
case "carson":
PROPER1="Fort Carson";
break;
case "drum":
PROPER1="Fort Drum";
break;
case "eustis":
PROPER1="Fort Eustis";
break;
case "gordon":
PROPER1="Fort Gordon";
break;
case "hood":
PROPER1="Fort Hood";
break;
case "huachuca":
PROPER1="Fort Huachuca";
break;
case "irwin":
PROPER1="Fort Irwin";
break;
case "jackson":
PROPER1="Fort Jackson";
break;
case "knox":
PROPER1="Fort Knox";
break;
case "leavenworth":
PROPER1="Fort Leavenworth";
break;
case "lee":
PROPER1="Fort Lee";
break;
case "wood":
PROPER1="Fort Leonard Wood";
break;
case "lewis":
PROPER1="Fort Lewis";
break;
case "meade":
PROPER1="Fort Meade";
break;
case "polk":
PROPER1="Fort Polk";
break;
case "riley":
PROPER1="Fort Riley";
break;
case "rucker":
PROPER1="Fort Rucker";
break;
case "samhouston":
PROPER1="Fort Sam Houston";
break;
case "sill":
PROPER1="Fort Sill";
break;
case "stewart":
PROPER1="Fort Stewart";
break;
case "story":
PROPER1="Fort Story";
break;
case "wainwright":
PROPER1="Fort Wainwright";
break;
case "europe":
PROPER1="Europe";
break;
case "hawaii":
PROPER1="Hawaii";
break;
case "hunter":
PROPER1="Hunter AAF";
break;
case "korea":
PROPER1="Korea";
break;
case "westpoint":
PROPER1="USMA West Point";
break;
case "washington":
PROPER1="Washington DC";
break;
case "other":
PROPER1="Other";
break;

}
switch(month){
case "April07":
PROPER2="April 2007";
break;

case "March07":
PROPER2="March 2007";
break;

case "February07":
PROPER2="February 2007";
break;

case "January07":
PROPER2="January 2007";
break;

case "December06":
PROPER2="December 2006";
break;

case "November06":
PROPER2="November 2006";
break;

case "October06":
PROPER2="October 2006";
break;

case "September06":
PROPER2="September 2006";
break;

case "August06":
PROPER2="August 2006";
break;

case "July06":
PROPER2="July 2006";
break;

case "June06":
PROPER2="June 2006";
break;

case "May06":
PROPER2="May 2006";
break;

case "April06":
PROPER2="April 2006";
break;

case "March06":
PROPER2="March 2006";
break;

case "February06":
PROPER2="February 2006";
break;

case "January06":
PROPER2="January 2006";
break;

case "December05":
PROPER2="December 2005";
break;

case "November05":
PROPER2="November 2005";
break;

case "October05":
PROPER2="October 2005";
break;

case "September05":
PROPER2="September 2005";
break;

case "August05":
PROPER2="August 2005";
break;

case "July05":
PROPER2="July 2005";
break;

case "June05":
PROPER2="June 2005";
break;

case "May05":
PROPER2="May 2005";
break;

case "April05":
PROPER2="April 2005";
break;

case "March05":
PROPER2="March 2005";
break;

case "February05":
PROPER2="February 2005";
break;

case "January05":
PROPER2="January 2005";
break;

case "December04":
PROPER2="December 2004";
break;

case "November04":
PROPER2="November 2004";
break;

case "October04":
PROPER2="October 2004";
break;

case "September04":
PROPER2="September 2004";
break;

case "August04":
PROPER2="August 2004";
break;

case "July04":
PROPER2="July 2004";
break;

case "June04":
PROPER2="June 2004";
break;

case "May04":
PROPER2="May 2004";
break;

case "April04":
PROPER2="April 2004";
break;

case "March04":
PROPER2="March 2004";
break;

case "February04":
PROPER2="February 2004";
break;

case "January04":
PROPER2="January 2004";
break;

case "December03":
PROPER2="December 2003";
break;

case "November03":
PROPER2="November 2003";
break;

case "October03":
PROPER2="October 2003";
break;

case "September03":
PROPER2="September 2003";
break;

case "August03":
PROPER2="August 2003";
break;

case "July03":
PROPER2="July 2003";
break;

case "June03":
PROPER2="June 2003";
break;

case "May03":
PROPER2="May 2003";
break;
case "April03":
PROPER2="April 2003";
break;

case "March03":
PROPER2="March 2003";
break;

case "February03":
PROPER2="February 2003";
break;

case "January03":
PROPER2="January 2003";
break;

case "December02":
PROPER2="December 2002";
break;

case "November02":
PROPER2="November 2002";
break;

case "October02":
PROPER2="October 2002";
break;

case "September02":
PROPER2="September 2002";
break;
case "August02":
PROPER2="August 2002";
break;

case "July02":
PROPER2="July 2002";
break;

case "June02":
PROPER2="June 2002";
break;
case "May02":
PROPER2="May 2002";
break;

case "April02":
PROPER2="April 2002";
break;
case "March02":
PROPER2="March 2002";
break;

case "February02":
PROPER2="February 2002";
break;

case "January02":
PROPER2="January 2002";
break;
case "December01":
PROPER2 ="December 2001";
break;

case "November01":
PROPER2="November 2001";
break;
case "October01":
PROPER2="October 2001";
break;
}

<!-- Beginning of JavaScript -

function jumpToNewSite() {
self.location=
//document.open(document.Form2.jumpTo.options[document.Form2.jumpTo.selectedIndex]);
document.Form2.jumpTo.options[document.Form2.jumpTo.selectedIndex].value;

return false;
}

// - End of JavaScript - -->
</SCRIPT>

<CENTER><img border="0" src="../injurybanner.gif" width="471" height="60"><CENTER>

<script language="javascript">

document.write("<FORM METHOD=LINK ACTION=F2.htm>");
document.write("<p align=center><table width=339 align=center><tr><td width=132 align=left>");
document.write("<p align=left>Choose a Location:</p></td><td width=196 align=left>");
document.write("<select name=CAMPin onChange =submit() >");
document.write("<option value="+camp+">"+PROPER1+"<option value=army>Army All<option value=aberdeen>Aberdeen Prov. Ground <option value=belvoir>Fort Belvoir <option value=benning>Fort Benning<option value=bliss>Fort Bliss<option value=bragg>Fort Bragg<option value=campbell>Fort Campbell");
document.write("<option value=carson>Fort Carson<option value=drum>Fort Drum<option value=eustis>Fort Eustis<option value=gordon>Fort Gordon<option value=hood>Fort Hood<option value=huachuca>Fort Huachuca<option value=irwin>Fort Irwin");
document.write("<option value=jackson>Fort Jackson<option value=knox>Fort Knox<option value=leavenworth>Fort Leavenworth<option value=lee>Fort Lee<option value=wood>Fort Leonard Wood<option value=lewis>Fort Lewis<option value=meade>Fort Meade");
document.write("<option value=polk>Fort Polk<option value=riley>Fort Riley<option value=rucker>Fort Rucker<option value=samhouston>Fort Sam Houston<option value=sill>Fort Sill<option value=stewart>Fort Stewart<option value=story>Fort Story<option value=wainwright>Fort Wainwright");
document.write("<option value=europe>Europe<option value=hawaii>Hawaii<option value=hunter>Hunter AAF<option value=korea>Korea<option value=westpoint>USMA West Point<option value=washington>Washington DC </select>");

document.write("</td></tr><tr><td width=132 align=left> <p align=left>Choose a Report:&nbsp &nbsp</td><td width=196 align=left>");
document.write("<select name=MONTHin onChange=submit()><option value="+month+">"+PROPER2+" <option value=April07>April 2007<option value=March07>March 2007<option value=February07>February 2007<option value=January07>January 2007<option value=December06>December 2006<option value=November06>November 2006<option value=October06>October 2006<option value=September06>September 2006<option value=August06>August 2006<option value=July06>July 2006<option value=June06>June 2006<option value=May06>May 2006<option value=April06>April 2006<option value=March06>March 2006<option value=February06>February 2006<option value=January06>January 2006<option value=December05>December 2005<option value=November05>November 2005<option value=October05>October 2005<option value=September05>September 2005<option value=August05>August 2005<option value=July05>July 2005<option value=June05>June 2005<option value=May05>May 2005<option value=April05>April 2005<option value=March05>March 2005<option value=February05>February 2005<option value=January05>January 2005<option value=December04>December 2004<option value=November04>November 2004<option value=October04>October 2004<option value=September04>September 2004<option value=August04>August 2004<option value=July04>July 2004<option value=June04>June 2004<option value=May04>May 2004<option value=April04>April 2004<option value=March04>March 2004<option value=February04>February 2004<option value=January04>January 2004<option value=December03>December 2003<option value=November03>November 2003<option value=October03>October 2003<option value=September03>September 2003 <option value=August03>August 2003<option value=July03>July 2003<option value=June03>June 2003<option value=May03>May 2003<option value=April03>April 2003<option value=March03>March 2003<option value=February03>February 2003<option value=January03>January 2003<option value=December02>December 2002<option value=November02>November 2002<option value=October02>October 2002<option value=September02>September 2002<option value=August02>August 2002<option value=July02>July 2002<option value=June02>June 2002<option value=May02>May 2002<option value=April02>April 2002<option value=March02>March 2002<option value=February02>February 2002<option value=January02>January 2002 <option value=December01>December 2001 <option value=November01>November 2001 <option value=October01>October 2001</select>");

document.write("</td></tr></table>");
document.write("</Form>");


document.write("<center><td width=517><table border=0 cellpadding=12><tr>");
document.write(" <td align=center><strong><font size=2>");
document.write(" <a href="+ camp +"/"+ month +"/"+ camp +"1.pdf target=_top>Injury Trends </a></font></strong></td>");
document.write(" <td align=center><strong><font size=2><a href="+ camp +"/"+ month +"/"+ camp +"2.pdf target=_top>Causes of<br>");
document.write(" Serious Injury</a></font></strong></td>");
document.write("<td align=center><strong><font size=2><a href="+ camp +"/"+ month +"/"+ camp +"3.pdf target=_top>Medical<br>");
document.write(" Encounters</a></font></strong></td>");
document.write("<td align=center><strong><font size=2><a href="+ camp +"/"+ month +"/"+ camp +"4.pdf target=_top>Soldier<br>");
document.write(" Duty Status</a></font></strong></td>");
document.write("<td align=center><strong><font size=2><a href="+ camp +"/"+ month +"/"+ camp +".pdf target=_top>View<br>");
document.write("Entire Report</a></font></strong></td>");
document.write("</tr>");
document.write("<tr>");
document.write("<td align=center><strong><a href="+ camp +"/"+ month +"/"+ camp +"1.pdf target=_top><img border=0 src=../injurytrends.gif width=77 height=97></a></strong></td>");
document.write("<td align=center>");
document.write(" <p align=center><strong><a href="+ camp +"/"+ month +"/"+ camp +"2.pdf target=_top><img border=0 src=../causes.gif width=74 height=97></a></strong></td>");
document.write("<td align=center>");
document.write(" <p align=center><strong><a href="+ camp +"/"+ month +"/"+ camp +"3.pdf target=_top><img border=0 src=../medical.gif width=73 height=97></a></strong></td>");
document.write(" <td align=center><strong><a href="+ camp +"/"+ month +"/"+ camp +"4.pdf target=_top><img border=0 src=../last.gif width=75 height=97></a></strong></td>");
document.write(" <td align=center><strong><a href="+ camp +"/"+ month +"/"+ camp +".pdf target=_top><img border=0 src=../Front.gif width=74 height=97></a></strong></td>");
document.write("</tr></table><p align=center>&nbsp<p align=center>&nbsp</div></center><p align=center>&nbsp</p>");
document.write("</form>");

</script>

</center></center></body>
</html>

anessa05
05-07-2007, 02:19 PM
Hi Degsy, Thanks for your help. I tried the test code from BrainJar, setting it to point to my file folder, but it didn't work. I received the following error...

Microsoft VBScript compilation error '800a0409'

Unterminated string constant

/ASPTest/listfiles.asp, line 70

Response.Write("<li>
--------------------^

Line 70 is...
Response.Write("<li>

How can I fix this to work?

Spudhead
05-09-2007, 02:36 PM
Response.Write("<li>")

As a general rule, if it's got an open bracket, it needs a close bracket. And if it's got an open quote, it needs a close quote.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum