Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
i used the following code to download the file folder in asp.net website are

 string path = @"E:\sample.zip";
        FileInfo file = new FileInfo(path);
           int len = (int)file.Length, bytes;
             Response.ContentType = "text/html";  
          // Response.AddHeader "Content-Disposition", "attachment;filename=" + filename; 
             Response.AppendHeader("content-length", len.ToString());
           byte[] buffer = new byte[1024];

        using(Stream stream = File.OpenRead(path)) {
    while (len > 0 && (bytes =
        stream.Read(buffer, 0, buffer.Length)) > 0)
    {
        Response.OutputStream.Write(buffer, 0, bytes);
        len -= bytes;
    }
}

it works fine/...

but my problem is when i used the same code to the library file as

C#
FileInfo file = new FileInfo(ZipPath);
            int len = (int)file.Length, bytes;
            HttpResponse Response = new HttpResponse(TextWriter.Null);
            Response.ContentType = "text/html";
            Response.AppendHeader("content-length", len.ToString());
            byte[] buffer = new byte[1024];

            using (Stream stream = File.OpenRead(ZipPath))
            {
                while (len > 0 && (bytes =
                    stream.Read(buffer, 0, buffer.Length)) > 0)
                {
                    Response.OutputStream.Write(buffer, 0, bytes);
                    len -= bytes;
                }
            }
        }


it throws me a error as

OutputStream is not available when a custom TextWriter is used.

i guess the problem is in that line

HttpResponse Response = new HttpResponse(TextWriter.Null);

can you provide me a solution

waiting for your responses....
Posted

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900