(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.ClearC ontent();
Stream remoteStream = null;
WebResponse response = null;
string file = "http://www.xyz.com/n.ppt";or //localhost/scripts/n.ppt.
WebRequest request = WebRequest.Crea te(file);
if (request != null)
{
// Send the request to the server and retrieve the
// WebResponse object
response = request.GetResp onse();
if (response != null)
{
// Once the WebResponse object has been retrieved,
// get the stream object associated with the response's data
remoteStream = response.GetRes ponseStream();
byte[] Buffer = new byte[response.Conten tLength];
remoteStream.Re ad (Buffer, 0, Buffer.Length);
string extension = System.IO.Path. GetExtension(fi le);
if(extension.St artsWith("."))
extension = extension.Subst ring(1); Response.Conten tType="applicat ion/"+extension ;
Response.AddHea der( "content-disposition","i nline; filename=n.ppt" );
Response.Binary Write(Buffer);
}
}
-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)
<Id>tEwBVAYN4ku F1MaR4odcGQ==</Id>