I'm new to HTML.
What is the HTML <a href> code/syntax to download a file to a different name than what is on the server?
I have many files stored on the server with cryptic file names, but I would like the files to be downloaded and saved with a "friendly name".
Is there a way to do this just by using the <a href> command?
12 3762
html cannot do this. In fact, it is not a function of the browser at all.
Hi coetzecc,
If you are using ASP or PHP to serve up your file, you can use HTTP headers to add the following info: - Content-Disposition:attachment;filename:yourfile.ext
.
If you have no idea what PHP or ASP are then let us know and we might be able to help you further.
Best regards,
medicineworker
hi medicineworker,
Thanks for your reply.
Let me give you a bit more info.
I'm trying to extract files form WSUS. I found a utility on the web to do exactly that. Now I'm trying to improve it a little.
The page is written in ASP. It uses SQL to query a database and returns one or more results. I am then able to download the file but the filename is long and cryptic.
The search results include the long cryptic name plus the "friendly name".
I'd like to use that friendly for the downloads instead of the cryptic name.
Here is a excerpt of the ASP code: Dim objConn, sqlString -
Set objConn = Server.CreateObject("ADODB.Connection")
-
objConn.Open "HotfixInfo"
-
-
Dim rs
-
sqlString = "SELECT FileName, MUURL, FileDigest " & _
-
"FROM tbFile " & _
-
"WHERE FileName like '%" & sSearch & "%' " & _
-
"and FileName not like '%psf%' " & _
-
"and FileName not like '%express%' " & _
-
"ORDER BY FileName"
-
-
set rs = objConn.Execute(sqlString)
-
-
If Not rs.eof Then
-
Do While Not rs.eof
-
Dim sFileName, sFileLocation, sFourtyChr, sFileDir,sFileDirFull, sFileFull, sFileWeb
-
sFileName = rs(0)
-
sFileLocation = rs(1)
-
sFourtyChr = right(sFileLocation, 44)
-
sFileDir = right(sFileLocation, 6)
-
sFileDir = left(sFileDir, 2)
-
sFileDirFull = sWSUSContentDir+sFileDir
-
sFileFull = sFileDirFull+"\"+sFourtyChr
-
sFileWeb = sWSUSContentSrv+sFileDir+"/"+sFourtyChr
-
-
'Checks if the hotfix file exist
-
If (fso.FileExists(sFileFull)) Then
-
Dim sLink
-
sLink = ("<a href="""+sFileWeb+""">"+sFileName+"</a>"
-
%>
-
<tr>
-
<td colspan="2" class="content"><%= sLink %></td>
-
<td colspan="2" class="content"><%= sFourtyChr %></td>
-
<td colspan="2" class="content"><%= sFileDigest %></td>
-
</tr>
-
<%
-
End If
-
rs.MoveNext
-
Loop
-
Else
-
%>
-
<tr>
-
<td colspan="6" class="content" align="center"><br>
-
<h2>There are no files with the search string [<%= sSearch %>] available<br>
-
Tip: Search with the KB article number.</h2><br>
-
</td>
-
</tr>
-
<%
-
End If
I'm not sure where to insert you suggested code.
Any suggestions?
Since this is an asp question, you would get more help on that board, where I can transfer this, but I need to know if it's ASP or ASP.NET.
Since this is an asp question, you would get more help on that board, where I can transfer this, but I need to know if it's ASP or ASP.NET.
Well WSUS setup requires ASP to be installed on the server. So I presume it's ASP.
Can anyone help me with this, please?
Hi coetzecc,
I am unfortunately a bit busy today working on other projects but I will look into your query tomorrow morning and work out some kind of solution (which will involve an intermediary ASP file to parse the filenames from the WSUS database).
Best regards,
medicineworker
Hi coetzecc,
I am unfortunately a bit busy today working on other projects but I will look into your query tomorrow morning and work out some kind of solution (which will involve an intermediary ASP file to parse the filenames from the WSUS database).
Best regards,
medicineworker
Thanks medicineworker. (eagerly awaiting your reply)
Hi coetzecc,
This is the code provision I came up with. Notice the comments (marked here in
) which explains what I have done and how I have done it.
This is your current code: -
Dim objConn, sqlString
-
Set objConn = Server.CreateObject("ADODB.Connection")
-
objConn.Open "HotfixInfo"
-
-
Dim rs
-
sqlString = "SELECT FileName, MUURL, FileDigest " & _
-
"FROM tbFile " & _
-
"WHERE FileName like '%" & sSearch & "%' " & _
-
"and FileName not like '%psf%' " & _
-
"and FileName not like '%express%' " & _
-
"ORDER BY FileName"
-
-
set rs = objConn.Execute(sqlString)
-
-
If Not rs.eof Then
-
Do While Not rs.eof
-
Dim sFileName, sFileLocation, sFourtyChr, sFileDir,sFileDirFull, sFileFull, sFileWeb
-
sFileName = rs(0)
-
sFileLocation = rs(1)
-
sFourtyChr = right(sFileLocation, 44)
-
sFileDir = right(sFileLocation, 6)
-
sFileDir = left(sFileDir, 2)
-
sFileDirFull = sWSUSContentDir+sFileDir
-
sFileFull = sFileDirFull+"\\"+sFourtyChr
-
sFileWeb = sWSUSContentSrv+sFileDir+"/"+sFourtyChr
-
-
'Checks if the hotfix file exist
-
If (fso.FileExists(sFileFull)) Then
-
Dim sLink
-
'Added link to ASP file (code further down) which will parse your link value and rename the "attachment" as such into a friendly name
-
sLink = ("<a href=""filedownloader.asp?fn="+sFileWeb+"&ffn="+sFileName+""">"+sFileName+"</a>"
-
%>
-
<tr>
-
<td colspan="2" class="content"><%= sLink %></td>
-
<td colspan="2" class="content"><%= sFourtyChr %></td>
-
<td colspan="2" class="content"><%= sFileDigest %></td>
-
</tr>
-
<%
-
End If
-
rs.MoveNext
-
Loop
-
Else
-
%>
-
<tr>
-
<td colspan="6" class="content" align="center"><br>
-
<h2>There are no files with the search string [<%= sSearch %>] available<br>
-
Tip: Search with the KB article number.</h2><br>
-
</td>
-
</tr>
-
<%
-
End If
-
Code for filedownloader.asp: -
<%@Language="VBScript"%>
-
<%Option Explicit%>
-
<%Response.Buffer = True%>
-
<%
-
On Error Resume Next
-
Dim strPath
-
'Get web path to file from "fn" QueryString
-
strPath = CStr(Request.QueryString("fn"))
-
'-- do some basic error checking for the QueryString
-
If strPath = "" Then
-
Response.Clear
-
Response.Write("No file specified.")
-
Response.End
-
ElseIf InStr(strPath, "..") > 0 Then
-
Response.Clear
-
Response.Write("Illegal folder location.")
-
Response.End
-
ElseIf Len(strPath) > 1024 Then
-
Response.Clear
-
Response.Write("Folder path too long.")
-
Response.End
-
Else
-
Call DownloadFile(strPath)
-
End If
-
-
Private Sub DownloadFile(file)
-
'--declare variables
-
Dim strAbsFile
-
Dim strFileExtension
-
Dim objFSO
-
Dim objFile
-
Dim objStream
-
'-- set absolute file location
-
strAbsFile = Server.MapPath(file)
-
'-- create FSO object to check if file exists and get properties
-
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
-
'-- check to see if the file exists
-
If objFSO.FileExists(strAbsFile) Then
-
Set objFile = objFSO.GetFile(strAbsFile)
-
'-- first clear the response, and then set the appropriate headers
-
Response.Clear
-
'-- the filename you give it will be the one that is shown
-
' to the users by default when they save
-
' med: added "friendly" file name capability (passed from "ffn" QueryString)
-
Response.AddHeader "Content-Disposition", "attachment; filename=" & Request.QueryString("ffn")
-
Response.AddHeader "Content-Length", objFile.Size
-
Response.ContentType = "application/octet-stream"
-
Set objStream = Server.CreateObject("ADODB.Stream")
-
objStream.Open
-
'-- set as binary
-
objStream.Type = 1
-
Response.CharSet = "UTF-8"
-
'-- load into the stream the file
-
objStream.LoadFromFile(strAbsFile)
-
'-- send the stream in the response
-
Response.BinaryWrite(objStream.Read)
-
objStream.Close
-
Set objStream = Nothing
-
Set objFile = Nothing
-
Else 'objFSO.FileExists(strAbsFile)
-
Response.Clear
-
Response.Write("No such file exists.")
-
End If
-
Set objFSO = Nothing
-
End Sub
-
%>
-
Note that this code was taken and modified from http://www.xefteri.com/articles/show.cfm?id=7 and they deserve
the credit for this code - I simply modified it for your usage.
Hope it helps.
Best regards,
medicineworker
Thank you so much medicineworker.
I will try to implement your code and let you know if I get it to work.
IT WORKS!!!
Thanks a million medicineworker! You're the MAN!
You're very welcome :-)
Any further questions on this subject, you are welcome to PM me anytime.
medicineworker
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Reply Via Newsgroup |
last post by:
Folks,
Say I have a table, ten columns, ten rows - Each with a word in it. I want
to change the values of some/all of the cells in the table via a hyperlink.
How do I reference each cell and...
|
by: Steve Mauldin |
last post by:
I am having an issue with Mac IE users that come to an asp page on my site.
The page does a response.redirect to a PDF page. the PDF is downloaded onto
the desktop and saved as the name of the ASP...
|
by: who be dat? |
last post by:
Hello all. I'm writing an application that is writing trace information
that can be viewed in trace.axd. I would like to rename this and use a
different name specific to my application. I know...
|
by: ProJee |
last post by:
Hi,
Response.WriteFile (or Response.OutputStream.Write) finishes
immediately, not after the file is completely downloaded.
It finishes before (!) the user clicks the "Save" or "Open" browser...
|
by: balakrishnan.dinesh |
last post by:
hi frnds
I need to change the Browser settings dynamically in Onload
event through javascript. Like
Goto:
Tools->Internet Options -General -Settings -Check for newer
Versions of stored pages....
| |
by: Daniel Padron |
last post by:
Ok. Maybe I shouldnt post such basic questions here in such an advanced
group but my high school programming teacher wont answer any questions
outside of his curriculum :(
My goal is create a...
|
by: lawrence k |
last post by:
I've got a music studio for a client. Their whole studio is run with
Macintosh computers. Macintosh computers allow file names to have open
white spaces, such as "animal hospital.mp3".
I have a...
|
by: Andrew Jocelyn |
last post by:
Hi
How do I programmatically change (read/write) the values in this app.config
file at runtime? Specifically I want to change the client endpoint address
but it would be nice to change other...
|
by: Mateusz Viste |
last post by:
Hi,
I'm not sure if my question is really related to JavaScript, so please excuse me if that's not the case (and maybe you guys would have an idea what's the cause is and where could I ask)...
...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |