0

I am sending a file to client for download. File could be big (upto few GBs), so I am sending it in chunks. This is my code:

//code to get data in resp stream.
        using (Stream inputStream = resp.GetResponseStream())
        {
            if (System.IO.File.Exists(TargetFile))
            {
                System.IO.File.Delete(TargetFile);
            }
            using (FileStream fs = System.IO.File.Open(TargetFile, FileMode.Create, FileAccess.ReadWrite))
            {
                byte[] buffer = new byte[SegmentSize];
                int bytesRead;
                while ((bytesRead = inputStream.Read(buffer, 0, SegmentSize)) > 0)
                {
                    fs.Write(buffer,0,bytesRead);
                }
                Response.AddHeader("Content-Disposition", "Attachment;filename=targetFileName.pdf");
                return File(fs, "application/pdf");
            }
        }

When I click on the link to download it gives me above error. I tried with returning nothing and in that case it downloads the file but size of the file is zero. The error is in the last line.

1

1 Answer 1

0

I was having the same issue attaching the uploaded file(s) to an email. Adding the below to the web.config worked:

<system.web>
    <httpRuntime executionTimeout="90" maxRequestLength="20000"  useFullyQualifiedRedirectUrl="false" requestLengthDiskThreshold="8192"/>
</system.web>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.