I have a line of code in a button click event for a web page asp:button control that opens a selected ZIP file for downloading by the client when the button is clicked. It works fine using FireFox. Chrome, Opera, and Safari, and opens a download dialog box
in each browser. However, when using the script in IE 8 the browser opens a new window, and then immediately closes it without ever prompting to download the selected ZIP file. The script manager JAVA script line of code is shown below. The two object varibles
shown in the code, DownloadURL and UserFile, are module level object varibles that already contain the URL path, and the name of the ZIP file when the button click event occurs.
I have turned off private filtering and browsing, and set security to prompt for download, but nothing seems to work. Since the script works fine with the other browsers, I am guessing that maybe IE 8 has some type of gotcha I haven't found yet. Does anyone
have any idea what is causing this malfunction? I would just ignore it, but from the web site stats report, a good portion of the browers hitting the site are IE 8 and I don't want to punish them for their browser choice.
I would like to suggest you use the "Content-Disposition" header to tell the browser to download and that you would like the "Save" dialog box to ask the user what to do.
protected void downloadButton_Click(object sender, EventArgs e)
{
//prompt download save or open
Response.Clear();
Response.AppendHeader("content-disposition", "attachment; filename=" + fileName);
Response.ContentType = "application/zip";
Well I was hoping this would work but now I am getting an access error, both on the local development server when I test it and on the live hosting server when I uploaded the changes. The code you suggested reguires the hosting path and not the HTTP URL,
so I changed the object varible to the local hosting path (different on both, I use a different web.config for each) but the error says I do not have permissions to access the local path no matter whether it is my local development server or the online hosting
server: See changed code below ....
Protected Sub ButtonDownload_Click(sender As Object, e As System.EventArgs) Handles ButtonDownload.Click
Dim BType As String = ""
If CheckRegistration(RegCode) = True Then
BType = GetBrowserType()
If InStr(BType, "IE") > 0 Then
IEDownload()
Else
ScriptManager.RegisterStartupScript(Me, Me.GetType, "ZipDownload", ("window.open('" + DownloadURL + UserFile + "');"), True)
End If
Else
ScriptManager.RegisterStartupScript(Me, Me.GetType, "userConfirmation", ("var userConfirmation = window.alert('Download Name or code incorrect!'); __doPostBack('DeleteConfirmationPostBack', userConfirmation);"), True)
End If
End Sub
Sub IEDownload()
Dim FPath As String
Response.Clear()
Response.AppendHeader("content-disposition", ("attachment; filename=" + UserFile))
Response.ContentType = "application/zip"
FPath = DirectHostingPath + "Dir1\Dir2"
Response.WriteFile(FPath)
Response.Flush()
Response.End()
End Sub
As you can see I added a check for IE in the Download button click event and use the JAVA script if the browser is not IE. However, when I get the the line in the IEDownload routine "Response.WriteFile(FPath) it causes an Access Denied error. I have set permission
on both to allow read/write, and on the development server I even gaive anonymous access to the directory but nothing helped. It seems I am hitting a dead end.
I am sure it is some kind of IE protection thing or maybe even a flaw ... I will continue to research ... hopefully someone has had this issue before and know what to do. Thanks for your help anyway,.
Not only do you have to add the site to "Trusted Sites" but you also have to change the defaut settings for "Active Scripting" and "Scripting for Java Applets" from Disabled to Enabled in the "Trusted Sites".
Now even IE8+ works for this code:
Protected Sub ButtonDownload_Click(sender As Object, e As System.EventArgs) Handles ButtonDownload.Click
Dim URLString As String
If CheckRegistration(RegCode) = True Then
URLString = DownloadURL + UserFile
ScriptManager.RegisterStartupScript(Me, Me.GetType, "ZipDownload", ("var WOpenDL = window.open('" + URLString + "');"), True)
Else
ScriptManager.RegisterStartupScript(Me, Me.GetType, "userConfirmation", ("var userConfirmation = window.alert('Download Name or code incorrect!'); __doPostBack('DeleteConfirmationPostBack', userConfirmation);"), True)
End If
End Sub
Marked as answer by rdavidd on Jan 07, 2013 12:47 AM
rdavidd
Member
22 Points
26 Posts
IE 8 not opening a file in VB script manager JAVA script new window.open().
Jan 01, 2013 02:01 AM|LINK
I have a line of code in a button click event for a web page asp:button control that opens a selected ZIP file for downloading by the client when the button is clicked. It works fine using FireFox. Chrome, Opera, and Safari, and opens a download dialog box in each browser. However, when using the script in IE 8 the browser opens a new window, and then immediately closes it without ever prompting to download the selected ZIP file. The script manager JAVA script line of code is shown below. The two object varibles shown in the code, DownloadURL and UserFile, are module level object varibles that already contain the URL path, and the name of the ZIP file when the button click event occurs.
ScriptManager.RegisterStartupScript(Me, Me.GetType, "Download", ("window.open('" & DownloadURL & UserFile + "');"), True)I have turned off private filtering and browsing, and set security to prompt for download, but nothing seems to work. Since the script works fine with the other browsers, I am guessing that maybe IE 8 has some type of gotcha I haven't found yet. Does anyone have any idea what is causing this malfunction? I would just ignore it, but from the web site stats report, a good portion of the browers hitting the site are IE 8 and I don't want to punish them for their browser choice.
Yanping Wang...
Star
14886 Points
1534 Posts
Microsoft
Re: IE 8 not opening a file in VB script manager JAVA script new window.open().
Jan 03, 2013 05:17 AM|LINK
Hi rdavidd,
I would like to suggest you use the "Content-Disposition" header to tell the browser to download and that you would like the "Save" dialog box to ask the user what to do.
protected void downloadButton_Click(object sender, EventArgs e) { //prompt download save or open Response.Clear(); Response.AppendHeader("content-disposition", "attachment; filename=" + fileName); Response.ContentType = "application/zip";Response.WriteFile(filePath); Response.Flush(); Response.End(); }Hope this helps, thnaks.
Feedback to us
Develop and promote your apps in Windows Store
roopeshreddy
All-Star
20155 Points
3328 Posts
Re: IE 8 not opening a file in VB script manager JAVA script new window.open().
Jan 03, 2013 08:24 AM|LINK
Hi,
Did you tried adding your webiste to the Trusted Sites list in the Security tab of Internet Options?
If not try it!
Hope it helps u...
Roopesh Reddy C
Roopesh's Space
rdavidd
Member
22 Points
26 Posts
Re: IE 8 not opening a file in VB script manager JAVA script new window.open().
Jan 03, 2013 11:59 PM|LINK
Tried your idea fisrt since it was the quickest, and added the site to Trusted Sites ... but to no avail ... still not working ... thanks anyway.
rdavidd
Member
22 Points
26 Posts
Re: IE 8 not opening a file in VB script manager JAVA script new window.open().
Jan 04, 2013 12:25 AM|LINK
Well I was hoping this would work but now I am getting an access error, both on the local development server when I test it and on the live hosting server when I uploaded the changes. The code you suggested reguires the hosting path and not the HTTP URL, so I changed the object varible to the local hosting path (different on both, I use a different web.config for each) but the error says I do not have permissions to access the local path no matter whether it is my local development server or the online hosting server: See changed code below ....
Protected Sub ButtonDownload_Click(sender As Object, e As System.EventArgs) Handles ButtonDownload.Click Dim BType As String = "" If CheckRegistration(RegCode) = True Then BType = GetBrowserType() If InStr(BType, "IE") > 0 Then IEDownload() Else ScriptManager.RegisterStartupScript(Me, Me.GetType, "ZipDownload", ("window.open('" + DownloadURL + UserFile + "');"), True) End If Else ScriptManager.RegisterStartupScript(Me, Me.GetType, "userConfirmation", ("var userConfirmation = window.alert('Download Name or code incorrect!'); __doPostBack('DeleteConfirmationPostBack', userConfirmation);"), True) End If End Sub Sub IEDownload() Dim FPath As String Response.Clear() Response.AppendHeader("content-disposition", ("attachment; filename=" + UserFile)) Response.ContentType = "application/zip" FPath = DirectHostingPath + "Dir1\Dir2" Response.WriteFile(FPath) Response.Flush() Response.End() End SubAs you can see I added a check for IE in the Download button click event and use the JAVA script if the browser is not IE. However, when I get the the line in the IEDownload routine "Response.WriteFile(FPath) it causes an Access Denied error. I have set permission on both to allow read/write, and on the development server I even gaive anonymous access to the directory but nothing helped. It seems I am hitting a dead end.
I am sure it is some kind of IE protection thing or maybe even a flaw ... I will continue to research ... hopefully someone has had this issue before and know what to do. Thanks for your help anyway,.
rdavidd
Member
22 Points
26 Posts
Re: IE 8 not opening a file in VB script manager JAVA script new window.open().
Jan 07, 2013 12:47 AM|LINK
Found it!
Not only do you have to add the site to "Trusted Sites" but you also have to change the defaut settings for "Active Scripting" and "Scripting for Java Applets" from Disabled to Enabled in the "Trusted Sites".
Now even IE8+ works for this code:
Protected Sub ButtonDownload_Click(sender As Object, e As System.EventArgs) Handles ButtonDownload.Click Dim URLString As String If CheckRegistration(RegCode) = True Then URLString = DownloadURL + UserFile ScriptManager.RegisterStartupScript(Me, Me.GetType, "ZipDownload", ("var WOpenDL = window.open('" + URLString + "');"), True) Else ScriptManager.RegisterStartupScript(Me, Me.GetType, "userConfirmation", ("var userConfirmation = window.alert('Download Name or code incorrect!'); __doPostBack('DeleteConfirmationPostBack', userConfirmation);"), True) End If End Sub