rashidcm2004
New Member
On my ASP code, I have a LinkButton for my file upload:\[code\]<asp:Linkbutton ID="lnkContract" Text="" runat="server" Visible="false" onclick="lnkContract_Click"></asp:Linkbutton>\[/code\]I manage to write a code in C# that triggers a file download in \[code\]lnkContract_Click\[/code\] here:\[code\]protected void lnkContract_Click(object sender, EventArgs e){ string[] strFileType = lnkContract.Text.Split('.'); string strPath = Server.MapPath("~") + FilePath.CUST_DEALS + lnkContract.Text; Open(lnkContract.Text, strFileType[1], strPath);}private void Open(string strFile, string strType, string strPath){ FileInfo fiPath = new FileInfo(@strPath); //opens download dialog box try { Response.Clear(); Response.ContentType = "application/" + strType.ToLower(); Response.AddHeader("Content-Disposition", "attachment; filename=\"" + strFile + "\""); Response.AddHeader("Content-Length", fiPath.Length.ToString()); Response.TransmitFile(fiPath.FullName); HttpContext.Current.ApplicationInstance.CompleteRequest(); Response.Clear(); }//try catch { ucMessage.ShowMessage(UserControl_Message.MessageType.WARN, CustomerDefine.NOFILE); }//catch if file is not found}\[/code\]when I click the \[code\]LinkButton\[/code\] the file automatically downloads but when I open the file, it broken (or if the file is \[code\].jpeg\[/code\] the file shows an "x"). Where did I go wrong?