首页 > 编程 > .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.");

            }

        }
 


最大的网站源码资源下载站,

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表