国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

要用ASP.NET實現郵箱中附件下載的功能

2024-07-10 13:05:46
字體:
來源:轉載
供稿:網友
搞了好久也沒有搞通,網上有很多事例都是一樣的:ie支持的文件就會直接打開,而其它的像zip之類的文件不識別,就會彈出下載或打開的對話框。
突然一想是不是有什么文件篩選的問題,果然在寫文件之前將filter清除就可以像附件一樣使用了。

vb.net:
  dim filename as string =  "a.txt"
 
        if filename <> "" then
 
            dim path as string =  server.mappath(filename)
 
            dim file as system.io.fileinfo =  new system.io.fileinfo(path)
 
            if file.exists then
 
                response.clear()
 
                response.addheader("content-disposition", "attachment; filename=" + file.name)
 
                response.addheader("content-length", file.length.tostring())
 
                response.contenttype = "application/octet-stream"
 
                response.filter.close()
 
                response.writefile(file.fullname)
 
 
                response.end()
 
            else
 
                response.write("this file does not exist.")
 
            end if
 
        end if

----------------------------------------------------------------
c#:

   string filename = "a.txt";

        if (filename != "")
        {

            string path = server.mappath(filename);

            system.io.fileinfo file = new system.io.fileinfo(path);

            if (file.exists)
            {

                response.clear();

                response.addheader("content-disposition", "attachment; filename=" + file.name);

                response.addheader("content-length", file.length.tostring());

                response.contenttype = "application/octet-stream";

                response.filter.close();

                response.writefile(file.fullname);

              
                response.end();

            }

            else
            {

                response.write("this file does not exist.");

            }

        }
 


最大的網站源碼資源下載站,

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 涟源市| 长岭县| 博兴县| 桐柏县| 沧州市| 通渭县| 迁西县| 潞城市| 大埔县| 临漳县| 秀山| 崇左市| 栾川县| 阿坝县| 措勤县| 正阳县| 平顶山市| 龙海市| 新绛县| 衡东县| 古丈县| 措美县| 宜春市| 河池市| 新和县| 永春县| 德昌县| 沙雅县| 卢龙县| 晋宁县| 栾城县| 梅河口市| 阳信县| 江阴市| 麻江县| 青田县| 神木县| 上虞市| 宜州市| 利川市| 台山市|