specify title in file download

Results 1 to 2 of 2

Thread: specify title in file download

  1. #1
    Join Date
    Dec 1969

    Default specify title in file download

    hi,<BR><BR>i need to write some text to a file which the user can download. i used Response.ContentType = "text/plain" and the window pops which asking the user if he would like to view or sawe. When the user clicks on save, then another window pops up allowing the user to specify the path. Currently the default name of the file that is specified in this window is the name of the file which i used to generate the text, ie. generate.asp. how can i specify the default filename to be like names.txt?<BR><BR>thanks,<BR>anna

  2. #2
    Join Date
    Dec 1969

    Default Here ya go, just pass a filename to this sub...

    sub downloadfile (file) <BR> <BR> <BR> <BR> if ucase(left(file,3)) = "C:\" or ucase(left(file,3)) = "D:\" or ucase(left(file,3)) = "E:\" then<BR> FileName = file <BR> else<BR> FileName = server.mappath(file)<BR> end if<BR> <BR> &#039; clear the buffer<BR> Response.Buffer = True<BR> Response.Clear<BR><BR> &#039; create stream<BR> Set s = Server.CreateObject("ADODB.Stream")<BR> s.Open<BR><BR> &#039; set as binary<BR> s.Type = 1<BR><BR> &#039; load in the file<BR> on error resume next<BR><BR><BR> &#039; check the file exists<BR> Set fso = Server.CreateObject("Scripting.FileSystemObject")< BR> if not fso.FileExists(filename) then<BR> Response.Write("&#060;h1&#062;Error:&#060;/h1&#062;" & filename & " does not exist&#060;p&#062;")<BR> Response.End<BR> end if<BR><BR><BR> &#039; get length of file<BR> Set f = fso.GetFile(filename)<BR> intFilelength = f.size<BR><BR> <BR> s.LoadFromFile(filename)<BR> if err then<BR> Response.Write("&#060;h1&#062;Error: &#060;/h1&#062;" & err.Description & "&#060;p&#062;")<BR> Response.End<BR> end if<BR><BR> &#039; send the headers to the users browser<BR> Response.AddHeader "Content-Disposition", "attachment; filename=" & f.name<BR> Response.AddHeader "Content-Length", intFilelength<BR> Response.Charset = "UTF-8"<BR> Response.ContentType = "application/octet-stream"<BR><BR> &#039; output the file to the browser<BR> Response.BinaryWrite s.Read<BR> Response.Flush<BR><BR><BR> &#039; tidy up<BR> s.Close<BR> Set s = Nothing<BR><BR> <BR> <BR> <BR> <BR> <BR> end sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts