lucky Aman
lucky Aman

Reputation: 74

Force user to download a file

I want to force user to download a file. My website folder path is D:\websites\domain\ and file path is E:\folder\file.bak,

ASP - VBScript

<%

   Dim Stream
   Dim Contents
   Dim FileName
   FileName = "E:\db\A101.bak"
   Response.ContentType = "application/octet-stream"
   Response.AddHeader "content-disposition", "attachment; filename=" & FileName
   Set Stream = server.CreateObject("ADODB.Stream")
   Stream.Open
   Stream.LoadFromFile Server.MapPath(FileName)
   Contents = Stream.ReadText
   Response.BinaryWrite Contents
   Stream.Close
   Set Stream = Nothing

%>

its working perfectly if file is inside my website folder, But if i use the path E:\db\A101.bak give me an error, File not Found. i can't move file inside the Website folder due to security reasons. Help me

Upvotes: 1

Views: 2827

Answers (1)

AardVark71
AardVark71

Reputation: 4116

Since you already know your physical path you don't need the Server.MapPath method. (This method is normally used to translate a virtual path to a physical path) The Server.MapPath method probably does not work for a path outside the website's structure...

So, try using

Stream.LoadFromFile FileName

Upvotes: 2

Related Questions