Solved

Javascript: Change file name before downloading file

Posted on 2009-05-13
2
1,652 Views
Last Modified: 2012-06-27
Hi,

I am creating a ASP (Classic) application that is basically a Windows Explorer style app used to upload and store files on the fileserver, for some users.   Other users will only be able to download those files.

The app is database driven  I keep track of virtual folders and permissions in the database, the files are stored in a central directory by the FileID (i.e. 13.doc, 47.pdf, etc.).

When someone is going to download a file I would like to take the filename on the system (for example 47.pdf) and change it to the file description (i.e. Outline.pdf) before the user is prompted to open the file or save it on their computer.

Hopefully this post makes sense.  Is this even possible?

BTW: The ASP server is a third-party server so I can't install anything on it.

0
Comment
Question by:jfrent
2 Comments
 
LVL 12

Accepted Solution

by:
alien109 earned 500 total points
Comment Utility
http://support.microsoft.com/kb/260519

I believe this is relevant to what you are looking for. You should be able to set the filename that you want.
0
 
LVL 2

Author Comment

by:jfrent
Comment Utility
Thanks for the info.  That was a big help.  It pushed me in the right direction.  Here is my test script that works as I wanted it to (just in case it will help someone else):

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
      Const adBinary = 1
      Dim bStream
      Dim bBinaryFile
      Dim strFileName
      
      Set bStream = CreateObject("ADODB.Stream")
      strFilename = server.MapPath("30.xls")
      
      'Specify stream type as binary
      bStream.Type = adBinary
      
      'Open the stream
      bStream.Open
      
      'Load the file
      bStream.LoadFromFile strFileName
      
      'Read the stream
      bBinaryFile = bStream.Read
      
      'Output to browser
      Response.AddHeader "content-disposition","attachment; filename=MyDoc.xls"
      Response.BinaryWrite(bBinaryFile)
%>

This is slightly different than the Microsoft solution but there is no need to create and register a DLL file this way.  Worked in both IEv7 and Firefox.

 
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now