Creating Zip file from stream and downloading it

2 things. First, if you keep the code design you have, you need to perform a Seek() on the MemoryStream before writing it into the entry. dt.TableName = “Declaration”; MemoryStream stream = new MemoryStream(); dt.WriteXml(stream); stream.Seek(0,SeekOrigin.Begin); // <– must do this after writing the stream! using (ZipFile zipFile = new ZipFile()) { zipFile.AddEntry(“Report.xml”, “”, stream); … Read more

Difference between java.io.PrintWriter and java.io.BufferedWriter?

PrintWriter gives more methods (println), but the most important (and worrying) difference to be aware of is that it swallows exceptions. You can call checkError later on to see whether any errors have occurred, but typically you’d use PrintWriter for things like writing to the console – or in “quick ‘n dirty” apps where you … Read more

How can one flush input stream in C?

fflush(stdin) is undefined behaviour(a). Instead, make scanf “eat” the newline: scanf(“%s %d %f\n”, e.name, &e.age, &e.bs); Everyone else makes a good point about scanf being a bad choice. Instead, you should use fgets and sscanf: const unsigned int BUF_SIZE = 1024; char buf[BUF_SIZE]; fgets(buf, BUF_SIZE, stdin); sscanf(buf, “%s %d %f”, e.name, &e.age, &e.bs); (a) See, … Read more

OutOfMemoryException when send big file 500MB using FileStream ASPNET

I’ve created download page which allows user to download up to 4gb (may be more) few months ago. Here is my working snippet: private void TransmitFile(string fullPath, string outFileName) { System.IO.Stream iStream = null; // Buffer to read 10K bytes in chunk: byte[] buffer = new Byte[10000]; // Length of the file: int length; // … Read more