Trace not enabled ? All HTML stripped ? (using Response.Clear allows to make
sure you won't have a character coming from your APSX markup).
IMO The easiest path is to save the file (possibly using a content
disposition header) so that you can check the length. If not the length you
can do a file comparison to see where the file is corrupted.
--
Patrice
<(E-Mail Removed)> a écrit dans le message de news:
(E-Mail Removed)...
> For my application, there users can upload and download files to the a
> webserver. Straightforward enough. However, when they upload a PDF
> file then try to download it, the file seems to be corrupted. The had
> not been a problem before but it seems to have been introduced when I
> refactored the writing to the response to a buffered version to prevent
> potential OutOfMemoryExceptions (you wouldn't believe the size of some
> of these files...).
>
> Here's the code (pretty much jacked from a Microsoft knowledge base
> article):
>
> private void WriteToResponse(string filepath, string contentType,
> NameValueCollection extraHeaders)
> {
> Stream iStream = null;
>
> // Buffer to read 10K bytes in chunk:
> byte[] buffer = new Byte[10000];
>
> // Length of the file:
> int length;
>
> // Total bytes to read:
> long dataToRead;
>
> // Identify the file name.
> string filename = Path.GetFileName(filepath);
>
> try
> {
> // Open the file.
> iStream = new FileStream(filepath, FileMode.Open,
> FileAccess.Read, FileShare.Read);
>
>
> // Total bytes to read:
> dataToRead = iStream.Length;
>
> Response.ContentType = contentType;
> if(extraHeaders != null)
> {
> for (int i = 0; i < extraHeaders.Count; i++)
> {
> Trace.Write("adding Key value: " +
> extraHeaders.GetKey(i)
> + ". Adding value: " +
> extraHeaders[i]);
> Response.AddHeader(extraHeaders.GetKey(i),
> extraHeaders[i]);
> }
> }
>
> // Read the bytes.
> while (dataToRead > 0)
> {
> // Verify that the client is connected.
> if (Response.IsClientConnected)
> {
> // Read the data in buffer.
> length = iStream.Read(buffer, 0, 10000);
>
> // Write the data to the current output stream.
> Response.OutputStream.Write(buffer, 0, length);
>
> // Flush the data to the HTML output.
> Response.Flush();
>
> buffer = new Byte[10000];
> dataToRead = dataToRead - length;
> }
> else
> {
> //prevent infinite loop if user disconnects
> dataToRead = -1;
> }
> }
> }
> catch(IOException ioEx)
> {
> errorRow.Visible = true;
> lblErrorMsg.Text = ioEx.Message;
> log.Error(ioEx.ToString());
> }
> catch (Exception ex)
> {
> errorRow.Visible = true;
> // Trap the error, if any.
> log.Error(ex.ToString());
> }
> finally
> {
> if (iStream != null)
> {
> //Close the file.
> iStream.Close();
> }
> }
> }
>
> Thanks in advance for any help.
>