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);
}
}
--------------------------------
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);
}
}