Hi
I have a gridview which displays list of documents which are uploaded by admin. User will select checkbox in each row and clicks Download Selected button. The result should ask the user to save and download to client machine. So far it is working in my development system.
If I run from client, its not asking the user to save. Just opening a blank window and closing.
My code is as below
MainPage:
For i As Integer = 0 To arrFileNames.Count - 1
Dim strScript As New StringBuilder()
strScript.Append("<script language='javascript'>fnOpen('" + arrFileNames(i).ToString() + "');</script>")
ClientScript.RegisterStartupScript(Me.GetType(), arrFileNames(i).ToString(), strScript.ToString())
Next
<script language="javascript" type="text/javascript">
function fnOpen(fn)
{
window.open("Downloads.aspx?fn=" + fn,"","menubar=no, toolbar=no, location=no,scrollbars=yes,status=yes,width=500,height=300")
}
</script>
Downloads.aspx:
Dim filepath As String = Server.MapPath("~/Uploads/" & Request.QueryString("fn").ToString())
Dim file_info As New FileInfo(filepath)
' If file_info.Exists() Then
Response.Clear()
Response.AddHeader("Content-Disposition", "attachment; filename=" & file_info.Name)
Response.AddHeader("Content-Length", file_info.Length.ToString())
Response.ContentType = "application/msword"
Response.WriteFile(file_info.FullName)
Response.End()
Response.Flush()
'End If
***********************************************
Why is it not running in client machine?
By commenting the AddHeader and ContentType lines, its opening doc file even in the client machine.
Whats the problem?
I have a gridview which displays list of documents which are uploaded by admin. User will select checkbox in each row and clicks Download Selected button. The result should ask the user to save and download to client machine. So far it is working in my development system.
If I run from client, its not asking the user to save. Just opening a blank window and closing.
My code is as below
MainPage:
For i As Integer = 0 To arrFileNames.Count - 1
Dim strScript As New StringBuilder()
strScript.Append("<script language='javascript'>fnOpen('" + arrFileNames(i).ToString() + "');</script>")
ClientScript.RegisterStartupScript(Me.GetType(), arrFileNames(i).ToString(), strScript.ToString())
Next
<script language="javascript" type="text/javascript">
function fnOpen(fn)
{
window.open("Downloads.aspx?fn=" + fn,"","menubar=no, toolbar=no, location=no,scrollbars=yes,status=yes,width=500,height=300")
}
</script>
Downloads.aspx:
Dim filepath As String = Server.MapPath("~/Uploads/" & Request.QueryString("fn").ToString())
Dim file_info As New FileInfo(filepath)
' If file_info.Exists() Then
Response.Clear()
Response.AddHeader("Content-Disposition", "attachment; filename=" & file_info.Name)
Response.AddHeader("Content-Length", file_info.Length.ToString())
Response.ContentType = "application/msword"
Response.WriteFile(file_info.FullName)
Response.End()
Response.Flush()
'End If
***********************************************
Why is it not running in client machine?
By commenting the AddHeader and ContentType lines, its opening doc file even in the client machine.
Whats the problem?