99偷拍视频精品区一区二,口述久久久久久久久久久久,国产精品夫妇激情啪发布,成人永久免费网站在线观看,国产精品高清免费在线,青青草在线观看视频观看,久久久久久国产一区,天天婷婷久久18禁,日韩动漫av在线播放直播

asp.net實現(xiàn)網(wǎng)站上傳下載功能的幾種方法-創(chuàng)新互聯(lián)

能實現(xiàn)網(wǎng)站下載的功能語言都是動態(tài)語言,除了asp.net,還有php,jsp等,這里以asp.net為例。

創(chuàng)新互聯(lián)建站-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設、高性價比澧縣網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式澧縣網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設找我們,業(yè)務覆蓋澧縣地區(qū)。費用合理售后完善,10余年實體公司更值得信賴。

 這種可以實現(xiàn)多種網(wǎng)站下載功能, 代碼如下:

//TransmitFile實現(xiàn)下載
   protected void Button1_Click(object sender, EventArgs e)
    {

        Response.ContentType = "application/x-zip-compressed";
        Response.AddHeader("Content-Disposition", "p_w_upload;filename=z.zip");
       string filename = Server.MapPath("DownLoad/aaa.zip");
        Response.TransmitFile(filename);
    }

   //WriteFile實現(xiàn)下載
   protected void Button2_Click(object sender, EventArgs e)
    {

string fileName ="aaa.zip";//客戶端保存的文件名
       string filePath=Server.MapPath("DownLoad/aaa.zip");//路徑

        FileInfo fileInfo = new FileInfo(filePath);
        Response.Clear();
        Response.ClearContent();
        Response.ClearHeaders();
        Response.AddHeader("Content-Disposition", "p_w_upload;filename=" + fileName);
        Response.AddHeader("Content-Length", fileInfo.Length.ToString());
        Response.AddHeader("Content-Transfer-Encoding", "binary");
        Response.ContentType = "application/octet-stream";
        Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
        Response.WriteFile(fileInfo.FullName);
        Response.Flush();
        Response.End();

//WriteFile分塊下載
   protected void Button3_Click(object sender, EventArgs e)
    {

       string fileName = "aaa.zip";//客戶端保存的文件名
       string filePath = Server.MapPath("DownLoad/aaa.zip");//路徑

        System.IO.FileInfo fileInfo = new System.IO.FileInfo(filePath);

       if (fileInfo.Exists == true)
        {
           const long ChunkSize = 102400;//100K 每次讀取文件,只讀取100K,這樣可以緩解服務器的壓力
           byte[] buffer = new byte[ChunkSize];

            Response.Clear();
            System.IO.FileStream iStream = System.IO.File.OpenRead(filePath);
           long dataLengthToRead = iStream.Length;//獲取下載的文件總大小
            Response.ContentType = "application/octet-stream";
            Response.AddHeader("Content-Disposition", "p_w_upload; filename=" + HttpUtility.UrlEncode(fileName));
           while (dataLengthToRead > 0 && Response.IsClientConnected)
            {
               int lengthRead = iStream.Read(buffer, 0,

Convert.ToInt32(ChunkSize));//讀取的大小
                Response.OutputStream.Write(buffer, 0, lengthRead);
                Response.Flush();
                dataLengthToRead = dataLengthToRead - lengthRead;
            }
            Response.Close();
        }
    }

   //流方式下載
   protected void Button4_Click(object sender, EventArgs e)
    {
       string fileName = "aaa.zip";//客戶端保存的文件名
       string filePath = Server.MapPath("DownLoad/aaa.zip");//路徑

       //以字符流的形式下載文件
        FileStream fs = new FileStream(filePath, FileMode.Open);
       byte[] bytes = new byte[(int)fs.Length];
        fs.Read(bytes, 0, bytes.Length);
        fs.Close();
        Response.ContentType = "application/octet-stream";
       //通知瀏覽器下載文件而不是打開

Response.AddHeader("Content-Disposition", "p_w_upload;  filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
        Response.BinaryWrite(bytes);
        Response.Flush();
        Response.End();

    }

完畢(end)

另外有需要云服務器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。

文章題目:asp.net實現(xiàn)網(wǎng)站上傳下載功能的幾種方法-創(chuàng)新互聯(lián)
鏈接URL:http://www.yijiale78.com/article2/pssic.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化、自適應網(wǎng)站、網(wǎng)站設計公司、品牌網(wǎng)站建設外貿建站、標簽優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設