Download file using Response.TransmitFile is giving checksum mismatch

Ashwini Rao
Ashwini Rao used Ask the Experts™
on
I am using Response.TransmitFile to enable download feature on my web site and the file size is 2GB. It was working fine till last month. But now customers are complaining that the file downloaded from the size is corrupt. We tried on multiple browser and found the checksum is not matching. When we manually copy the files, checksum is matching. Files at source are not corrupt and is verified. Below is the code snippet used. Could this checksum mismatch is induced by web server? The file downloaded ends up being slightly more in file size compared to file in source. Please help.

            UserInfo objUserInfo = (UserInfo)Session["USER_INFO"];
            string strDocname = ((LinkButton)sender).CommandArgument.ToString();
            strDocname = strDocname.Replace("\r\n", "");
            strSource = ConfigurationManager.AppSettings["DOWNLOAD_PATH"].ToString() + Path.GetFileName(strDocname);
            new Log().logInfo("GotoSystem_onCommand", strSource);
            FileInfo file = new FileInfo(strDocname);
            Response.Clear();
            Response.ClearContent();
            Response.ClearHeaders();
            Response.ContentType = "application/octet-stream";
            Response.AppendHeader("Content-Disposition", "attachment; filename=" + strDocname + "");
            Response.TransmitFile(strSource);
            UpdateDownloadLog(objUserInfo.GetUserAcctId(), strDocname, Session["BRAND"].ToString());
            HttpContext.Current.ApplicationInstance.CompleteRequest();
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Programmer
Top Expert 2014
Commented:
Add Below Header in Code and try it
Response.AddHeader("Content-Length", file.Length.ToString());

Open in new window

And also make sure this I think it should be
   FileInfo file = new FileInfo(strSource );
Ashwini RaoSystem Architect

Author

Commented:
Brijesh,

Thanks so much. It worked, but not sure why we need to add this line. Could you explain this for my understanding?
Brijesh GandhiProgrammer
Top Expert 2014

Commented:
In past I also got this kind of error . So I am aware of this .. For more detail you can refer below link
Content Length
Need of Content Length

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial