zoukankan      html  css  js  c++  java
  • .net 实现的上传下载,如果是图片就显示上传的图片

    HTML:

            <div>
                <input id="fileUpload" type="file" runat="server" />
                <input id="btnFile" type="button" value="上传" runat="server" />
                <asp:Button ID="Button1" runat="server" Text="点击下载" OnClick="Button1_Click1" />
                <br />
                <br />
    
                <img alt="" src="<%=url%>" width="100" height="100" id="imgShow" />
            </div>

    后台代码:

    protected void Page_Load(object sender, EventArgs e)
            {
                btnFile.ServerClick += GetFile;
                
            }
            public string url = "";
    
            public void GetFile(object sender, EventArgs e) 
            {
                String[] Extensions = { ".gif", ".png", ".jpeg", ".jpg", ".bmp" };
                if (!Directory.Exists(Server.MapPath(@"/word/")))
                {
                    Directory.CreateDirectory(Server.MapPath(@"/word/"));
                }
    
                fileUpload.PostedFile.SaveAs(Server.MapPath(@"/word/") + fileUpload.Value);
    
                if (Extensions.Contains("." + fileUpload.Value.Split('.')[1]))
                {
                    url = @"/word/" + fileUpload.Value;
                }
            }
    
            protected void Button1_Click1(object sender, EventArgs e)
            {
                string strFileName = "典型病例.rtf";
                Response.ContentType = "application/x-zip-compressed";
                //Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312"); 
                string filename = @"E:个人练习MvcDemoWebTestword20160620140544" + strFileName;
                //为路径
                Response.AddHeader("Content-Disposition", "attachment;filename=" + Server.UrlPathEncode(strFileName));
                //Server.UrlPathEncode(); 解决文件名的乱码问题.
                Response.TransmitFile(filename); 
            }
  • 相关阅读:
    ZOJ3861 Valid Pattern Lock
    ZOJ 3866 Cylinder Candy
    hdu 1729 Stone Game SG函数
    hdu 2546 饭卡 01背包
    hdu 2084 数塔
    中国科学院大学生创新实践训练计划-
    中国科技论文在线期刊模板出现了格式问题,怎么解决?
    1015. 德才论 (25)
    1014. 福尔摩斯的约会 (20)
    Ubuntu 14.0的安装及联网
  • 原文地址:https://www.cnblogs.com/llcdbk/p/5600531.html
Copyright © 2011-2022 走看看