Download ms-word docs from server to client machine

Joined
Mar 23, 2009
Messages
3
Reaction score
0
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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top