Click here to Skip to main content
15,889,861 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
Hi i Have Designed a application in which i wil be uploading and Downloadint the File, When i Click a LInk Button to download a file a Post Back triggers and file is downloaded But the Prolem is when file is downloaded my UI Font becomes Bigger plz suggest to over come from this error



Code on Link Click
VB
Protected Sub lnkAttach_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkAttach.Click
        Dim jscript As String
        Dim download As String
        download = "download.aspx?FileId=" & lnkAttach.Text
        jscript = "<script>"
        jscript = jscript & "var winPrint=window.open('" & download & "', '', 'letf=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status=0');" & vbCrLf
              jscript = jscript & "</script>"

        HttpContext.Current.Response.Write(jscript)

    End Sub




Code In the download.aspx

VB
Dim strURL As String = "fileServer/" & Request.QueryString("FileId")

 Dim req As New WebClient()
 Dim response As HttpResponse = HttpContext.Current.Response
 response.Clear()
 response.ClearContent()
 response.ClearHeaders()
 response.Buffer = True
 response.AddHeader("Content-Disposition", "attachment;filename=" + Server.MapPath(strURL) + "")
 Dim data As Byte() = req.DownloadData(Server.MapPath(strURL))
 response.BinaryWrite(data)
 response.[End]()
Posted
Updated 14-Jun-12 23:58pm
v2

1 solution

Instead of writing it directly to the response stream, try the following.

VB
Dim downloadURL As String = String.Format("window.open('download.aspx?fileID={0}','_blank','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=400, height=400');", lnkAttach.Text)

ScriptManager.RegisterClientScriptBlock(Me, Me.GetType(), "download-file", downloadURL, True)  


Try this and let me know if it works.
 
Share this answer
 
v4
Comments
Diler Patel 15-Jun-12 6:30am    
Hi Pankaj i have updated my Question Plz Review it
Pankaj Nikam 15-Jun-12 6:56am    
Check this solution and do let me know if it works.`
Diler Patel 15-Jun-12 8:03am    
hey i Checked Out i gets a erroe Saying Invalid Arguments . . Just i have to write the above code in link button click right?
Pankaj Nikam 15-Jun-12 8:08am    
Have you copy pasted the code or changed it? It runs fine on my machine, I do get a popup... And yes you have to put that code in LinkButtonClick...
Diler Patel 15-Jun-12 8:12am    
ya i just Copied and Pasted And in my download.aspx page load i have the code it should be there or no?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900