I have this function made to save a PDF file in the local disk.
How do I automatically close the window after the download completed with an alert/msg box stating that the window will close?
This doesn't work:
Response.Write ("<script>alert('Save Finished'); self.close();</script>")
TheCode:
Private Function SaveLocal1(ByRef cnCon, ByVal PDFFile)
Dim ObjStream
Dim ObjFileSys
Dim Size
Dim fpath
Dim bdata
'Response.Write("<script>alert('local');</script>")
fpath = "C:\1.pdf" 'path of the file in the local server
filename = "LocalSave.pdf" 'name to be saved
'Response.Write("<script>alert('file paths');</script>")
Set ObjStream = Server.CreateObject("ADODB.Stream")
ObjStream.Open
ObjStream.Type = 1
ObjStream.LoadFromFile fpath
'Response.Write("<script>alert('server.createobject');</script>")
Response.buffer = TRUE
Response.AddHeader "Content-Disposition","attachment;filename="& filename & ";"
Response.ContentType = "application/pdf"
Set ObjFileSys = CreateObject("Scripting.FileSystemObject")
Size = ObjFileSys.GetFile(fpath).Size
bdata = ObjStream.Read(Size)
Response.BinaryWrite(bdata) 'the file will be saved in the downloads folder
Response.Write("<script>alert('Save to local finish');</script>")
ObjStream.Close
Set ObjStream = Nothing
Response.Flush
Response.End
Response.Write ("<script>alert('Save Finished'); self.close();</script>")
End Function