将不确定变成确定~Uri文本文件不用浏览器自动打开,而是下载到本地_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > 将不确定变成确定~Uri文本文件不用浏览器自动打开,而是下载到本地

将不确定变成确定~Uri文本文件不用浏览器自动打开,而是下载到本地

 2014/8/15 16:35:09  张占岭  程序员俱乐部  我要评论(0)
  • 摘要:回到目录这个标题有点长,简单来说就是,对于一个文件下载来说,是否可以提示用户,让它去保存,而不是将它在浏览器中打开,在浏览器中打开有个致命问题,那就是,如果你的页面编码和文件的编码不一致时,打开的就是乱码,本文事实上主要解决的就是这个问题。上面的URI格式的文件直接使用浏览器打开,由于文件编码是GB2312而网页编码是UTF-8,所以,页面上的文字就变成了乱码。知道了产生问题的根源之后,我们再来解决它,首先,我们没法去控制URI上的文件编码,所以,我们只能把它读到本地(WWW服务器)
  • 标签:文件 浏览 下载 浏览器

回到目录

这个标题有点长,简单来说就是,对于一个文件下载来说,是否可以提示用户,让它去保存,而不是将它在浏览器中打开,在浏览器中打开有个致命问题,那就是,如果你的页面编码和文件的编码不一致时,打开的就是乱码,本文事实上主要解决的就是这个问题。

JS5a1gq2lK641190rrr17xXXm+uGK63644vo4+nsc/UjVy9/m6ceavhNVtk4/Meq7Ceg/X6H1PYPuUfUqqe+r+imt1yL6gXVlaXrwyS3X//CZB5/cor5yQ1QrzXVj1sobfxbR61zda9AqWjfF1c/javVN962+6b7VN5vo/ojW3GJN8+9fM//+tQw9EE+/0GmBUesW/GLdgl8adatBv4poPanbzLQhottJPWim3/75nzdmvfjbZf+8/aENTC18aMPCh95Y+NAbCx/m6g5Nb/J0Z0SPqNrI1qPxtejXJtoU0eK4+s2mxb/ZdJe5HlP1Flu/jWqJprdNtFSnd6L6nU53x6SY5elbnvlGVM9yNf/Zy3V6zig6c0f1F02xfEwm78s5uoKnaI5//orbnv8mU7cb9Nf/oLWQJ+t5+oUr72DrKlJ3vnDVnS/S+paqRQbRmZsn63nacc1ixzV3sXXfH9696o6n7vvDu/Pucsxb4pi3ZLllcfL30peuNWrO5+mfvELrewZpOftVUt9XdQ+t14z6KVd0zn74ya3X3/30w09upXL5SnPdkLXyhp9F9DpP6crTq266b9VN96262UT3R7T6Fmuaf//q+dFsrdcDTFnP02sX/GLtgl8adStbuuR9m0G/IsVK3g8yFc3Tv/vz9huyXvjdsu2meTqO7ojo4Q136HI2S4+oepOpO9nS5fJFj8bX4riyl8vfYouRvN820RKmOLlcuezmp7m6RZWVNTdn5b2AXnNTK+9bjcvuy41Cnk53nn7gifeuXPjUA0+8J1eevnvFdXevuN5E8bO4LqN/m6cfafpOVC/r9GOjvqspO6oEk7dhza2Ks+y+h5aVNXd05U3n6Uf+uO36u59+5I/bTNbcTN2Q9doNP4toJU833msQnblfv4kr5GnTPK3TeoY4K+/IavvxZTtu+OkLjz+9g7fgXqgqbp5+aMMdD70RRzYSOTep3/moiWJr7rj69cZFv9642Fy/UbWJrceiir/yfuytux57a4lOyNOpydNmulIn63maoW+pWmQQnbl5iibsqxf97erF5nJcw9cDT2y+8vanHnhi87zFjnl3xdMSUtwUfq1RL+m09KVrl750HVcrrlua+jxtYc2tJmzuglu/7H451Xvj6c7Tjz710fVLlz361EdpydMM3cRVLGH/PK6i2fpmE8US9i0mul/T/PtXzY9mayviJvIFRq1d8AAjc99qECtt32YmVvL+FVPRhP34Mzt+cM/zjz+zg7PsXn/7g+ujOZuz4La/5jZdec/BPK3X0piUzdv+e/PWf2ze+o/3VG35x3tb/vEuoXc+jOijtz+I6q33o9r0/kebNm/buHnbxve2vfnetjff3fZGVFs3vLN1wztb17+9df3bW9e9tXXdW1vWbtqydtOWNZu2rNm4ZfXGLavf/HDVmx+ueuPD19/4cOUbH67c8OFrGz54bf0Hr67/4NV1H7yy7oNX1n2Qvfb9iF5e8/7La97/++qoVqzevGLV5hWrNr8U0eubl0e0cvPylZsdK98z6G+vMfTiqxBXG7d8/l9/XL5xy+cZ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0wAAAIC8IE8DAAAA8oI8DQAAAMgL8jQAAAAgL8jTAAAAgLwgTwMAAADygjwNAAAAyAvyNAAAACAvyNMAAACAvCBPAwAAAPKCPA0AAADIC/I0AAAAIC/I0wAAAIC8IE8DAAAA8oI8DQAAAMgL8jQAAAAgL8jTAAAAgLwgTwMAAADygjwNAAAAyAvyNAAAACAvyNMAAACAvCBPAwAAAPKCPA0AAADIy/8DejvW18epG0QAAAAASUVORK5CYII=" alt="" />

上面的URI格式的文件直接使用浏览器打开,由于文件编码是GB2312而网页编码是UTF-8,所以,页面上的文字就变成了乱码。

知道了产生问题的根源之后,我们再来解决它,首先,我们没法去控制URI上的文件编码,所以,我们只能把它读到本地(WWW服务器),然后再进行二次组织,并返回到客户端(自己的浏览器),对于URI的文件来说,我们不能直接返回,必须把它读成流之后,再返回,其实,.net为我们已经封装的很简便了,下面是实现的代码,大家看一下:

       /// <summary>
        /// 下载文件,同步支持本地和URI的文件
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public ActionResult DownLoad(string path)
        {
            if (path.IndexOf("http://") < 0)
            {
                string localPath = Server.MapPath("/" + path);
                string contentType = MimeMapping.GetMimeMapping(localPath);
                return File(localPath, contentType, "下载文件");
            }
            else
            {
                var url = new Uri(path);
                HttpWebRequest request = (HttpWebRequest)System.Net.WebRequest.Create(path);
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                Stream stream = response.GetResponseStream();
                var contentType = response.ContentType;//获得文件的总大小
                return File(stream, contentType, "下载文件");
            }
        }

下载是视频截图:

APP8yRD2KizzyrInlcA06kV5GRN73RWfoqJdQTW0OJ5IMy5ZwvhGmt2cK9yL5wISiW/zaMcKfP+KUf/V6k9iWb8MJ2THOT57V1djUN32fM/43camzNDm8rbGH0+zr2e5FDylVzUXyab3a+kibVUzGKTHqwbMc9/8kBEEMaFWmxmPqSS9QQW48ckXh2mYIL2bZKfic0QiJFFlEUugLYSKMiAew4foDxCQflgyIBAERQJACACIoEABCpA0Ua7yipD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MrI8KhVpXHD8hECRAOmiqoqU4iNVH5Jba5sAAADsSURBVFUNoGqryNgLaqJIgLQzwvciI8ujLIqM/UiI3X0UCZAuRv5C2/hqxan5r2ukC22LOiveISgSoFyq9ANEPW7SnVjVy8yUKDKRELnQBkgdVf2Ndg2puSLTAIoEKBcUWfOmVrsTSlsLRQIM+sOKzIzGhCIzKBKgTFpGe7Lv/mj9eAhTbA/oZFAkQEht/TUCqcF3vwVFAgBUEBQJACCCIgEARFAkAIAIigQAEEGRAAAiKBIAQARFAgCIoEgAABEUCQAggiIBAERQJACACIoEABApKLIGIxORSCRS6lNLS4s3AmMQkUgkUp2m/wfezsD0wJWtsAAAAABJRU5ErkJggg==" alt="" />

回到目录

发表评论
用户名: 匿名