using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace HySoft.BaseCallCenter.Web.faxmanage
{
    public partial class faxdown : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                if (Request.QueryString["path"] != null && Request.QueryString["path"].ToString() != "")
                {
                    try
                    {
                        HttpContext context = HttpContext.Current;
                        string path = context.Server.MapPath(Request.QueryString["path"].ToString());

                        int start = path.LastIndexOf("\\") + 1;
                        int end = path.Length;
                        string filename = path.Substring(start, end - start).Replace("|", "");
                        FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);

                        byte[] data = new byte[fs.Length];

                        fs.Read(data, 0, data.Length);

                        Response.Buffer = true;
                        Response.Clear();
                        Response.ClearContent();
                        Response.ClearHeaders();
                        Response.ContentType = "image/tiff";
                        Response.Charset = "utf-8";
                        Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
                        Response.AddHeader("Content-Disposition", "attachment;filename=" + filename + "");
                        Response.BinaryWrite(data);
                        Response.Flush();
                        Response.Close();
                    }
                    catch
                    { }
                }
            }
        }
    }
}