Problem in code for downloading files from web server.VIP

  • Thread starter Amol Guttal via .NET 247
  • Start date
A

Amol Guttal via .NET 247

(Type your message here)

--------------------------------
From: Amol Guttal
Hi,
This is the code which used to download a file from webserver.
If I point a file in my localhost for download it is working fine but when I point to a file in a remote server it is downloading the file but is corrupted and can't be open.
Please reply back soooooon.

Response.Clear();
Response.ClearContent();
Stream remoteStream = null;

WebResponse response = null;
string file = "http://www.xyz.com/n.ppt";or //localhost/scripts/n.ppt.
WebRequest request = WebRequest.Create(file);
if (request != null)
{
// Send the request to the server and retrieve the
// WebResponse object
response = request.GetResponse();
if (response != null)
{
// Once the WebResponse object has been retrieved,
// get the stream object associated with the response's data


remoteStream = response.GetResponseStream();

byte[] Buffer = new byte[response.ContentLength];
remoteStream.Read (Buffer, 0, Buffer.Length);
string extension = System.IO.Path.GetExtension(file);
if(extension.StartsWith("."))
extension = extension.Substring(1); Response.ContentType="application/"+extension ;
Response.AddHeader( "content-disposition","inline; filename=n.ppt");
Response.BinaryWrite(Buffer);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top