Showing posts with label Transfering file from server to client.. Show all posts
Showing posts with label Transfering file from server to client.. Show all posts

Monday, November 10, 2008

Transfering file from server to client.

Below code will give user option to
* User can download the file from the server and save it by choosing the save option.
* User can open the file.
* User can cancel the all operation.

using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
///
/// Summary description for TransmitFile
///


public class TransmitFile
{
public TransmitFile()
{
}
FileDownloadHelper objFileDownloadHelper = new FileDownloadHelper();
public void Transmit(string filePath,string FileName,string FileID)
{
FileInfo myfile = new FileInfo(filePath);
if (myfile.Exists)
{
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + FileName + "(" + FileID + ").doc");
HttpContext.Current.Response.AddHeader("Content-Length", myfile.Length.ToString());
HttpContext.Current.Response.ContentType = objFileDownloadHelper.ReturnExtension(myfile.Extension.ToLower());
HttpContext.Current.Response.TransmitFile(myfile.FullName);
HttpContext.Current.Response.End();
}
}
}