create class name general and inherit the interface class in it
Inheritance :
Inheritance allows us to define a class in terms of another class,
which makes it easier to create and maintain an application.
set the property and method for download by using httpresponse download the file from server to local system.
public class general : downloads
{
public string path
{
get;
set;
}
public void download()
{
using (FileStream fs = File.OpenRead(this.path))
{
int length = (int)fs.Length;
byte[] buffer;
using (BinaryReader br = new BinaryReader(fs))
{
buffer = br.ReadBytes(length);
}
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.AddHeader("content-disposition",
String.Format("attachment;filename={0}", Path.GetFileName(path)));
HttpContext.Current.Response.ContentType =
"application/" + Path.GetExtension(path).Substring(1);
HttpContext.Current.Response.BinaryWrite(buffer);
HttpContext.Current.Response.End();
} //
}
}
No comments:
Post a Comment