<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;

    namespace BaseProject.Classes.Util
    {
        public class DownLoadFile
        {
            public bool Down(string filepath)
            {
                HttpResponse response = HttpContext.Current.Response;
                bool succ = false;
                response.Clear();
                System.IO.Stream iStream = null;

                // Buffer to read 10K bytes in chunk:
                byte[] buffer = new Byte[10000];

                // Length of the file:
                int length;

                // Total bytes to read:
                long dataToRead;

                // Identify the file to download including its path.
                //  string filepath = "DownloadFileName";

                // Identify the file name.
                string filename = System.IO.Path.GetFileName(filepath);

                try
                {
                    // Open the file.
                    iStream = new System.IO.FileStream(filepath, System.IO.FileMode.Open,
                                System.IO.FileAccess.Read, System.IO.FileShare.Read);


                    // Total bytes to read:
                    dataToRead = iStream.Length;

                    response.ContentType = "application/octet-stream";
                    response.AddHeader("Content-Disposition", "attachment; filename=" + filename);

                    // Read the bytes.
                    while (dataToRead > 0)
                    {
                        // Verify that the client is connected.
                        if (response.IsClientConnected)
                        {
                            // Read the data in buffer.
                            length = iStream.Read(buffer, 0, 10000);

                            // Write the data to the current output stream.
                            response.OutputStream.Write(buffer, 0, length);

                            // Flush the data to the HTML output.
                            response.Flush();

                            buffer = new Byte[10000];
                            dataToRead = dataToRead - length;
                        }
                        else
                        {
                            //prevent infinite loop if user disconnects
                            dataToRead = -1;
                        }
                    }
                }
                catch (Exception ex)
                {
                    // Trap the error, if any.
                    response.Write("Error : " + ex.Message);
                }
                finally
                {
                    if (iStream != null)
                    {
                        //Close the file.
                        iStream.Close();
                    }
                }

                response.End();
                return succ;
            }
        }
    }

    posted on 2009-04-02 18:34 sanmao 閱讀(184) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     

    常用鏈接

    留言簿(5)

    隨筆分類

    隨筆檔案

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 久久久久成人精品免费播放动漫| 天堂亚洲免费视频| 99久久免费观看| 久久久久久亚洲精品| 99re6在线精品免费观看| 国产AV无码专区亚洲A∨毛片| 最新亚洲成av人免费看| 亚洲乱亚洲乱妇无码麻豆| 天堂在线免费观看| 久久亚洲美女精品国产精品 | 亚洲第一成年免费网站| 亚洲资源最新版在线观看| 国产卡二卡三卡四卡免费网址| 亚洲Av高清一区二区三区| 免费可以看黄的视频s色| 亚洲高清中文字幕免费| 日韩电影免费在线| 黄色网址免费在线观看| 亚洲Av无码精品色午夜| 国产男女爽爽爽爽爽免费视频| 亚洲一区在线观看视频| 国产一卡二卡≡卡四卡免费乱码 | 亚洲av无码一区二区三区观看| 黄色成人网站免费无码av| 亚洲AV噜噜一区二区三区| 亚洲区小说区图片区| 久久精品国产免费一区| 亚洲Av高清一区二区三区| 国产一级大片免费看| 国产精品99久久免费观看| 亚洲午夜国产精品无卡| 国产免费av片在线播放| 男人天堂免费视频| 亚洲人成人77777在线播放 | 亚洲av无码乱码在线观看野外| 91视频免费观看| www.av在线免费观看| 亚洲日韩精品无码一区二区三区| 69精品免费视频| 免费无码国产V片在线观看| 亚洲AV一宅男色影视|