Solved

Javascript: Change file name before downloading file

Posted on 2009-05-13
2
1,684 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
ID: 24380349
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
ID: 24380810
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
rhino JavaScript import, load 25 66
JQuery to parse xml string and get element by id 4 22
is this a cms? 8 34
Issues with Insert statement 12 8
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

911 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

16 Experts available now in Live!

Get 1:1 Help Now