asp.net实现上传文件显示本地绝对路径的实例代码

编程学习 2021-07-04 22:40www.dzhlxh.cn编程入门
asp.net实现上传图片显示本地绝对路径图片,其实这个还是得用<DIV></DIV>去显示图片会更好一点!用js实现图片的比例压缩让图片一样能够很清楚!狼蚁网站SEO优化把代码贴出来
页面代码主要就是JS
view plaincopy to clipboardprint
代码如下:

<head runat="server">
    <title>无标题页</title>
    <mce:script language="javascript" type="text/javascript"><!-- 
    function Imagesrc() 
    { 
    document.getElementById("image").src=document.all.FileUpload1.value; 
    }    
// --></mce:script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <img alt="\" id="image"  style="height:50px;width:50px" />
        <asp:FileUpload ID="FileUpload1" runat="server" onchange="Imagesrc()" />
        <br />
        <asp:Button ID="btnPost" runat="server"
            Text="上传" OnClick="btnPost_Click" /></div>
    </form>
</body>
<head runat="server">
    <title>无标题页</title>
    <mce:script language="javascript" type="text/javascript"><!--
    function Imagesrc()
    {
    document.getElementById("image").src=document.all.FileUpload1.value;
    }
// --></mce:script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <img alt="\" id="image"  style="height:50px;width:50px" />
        <asp:FileUpload ID="FileUpload1" runat="server" onchange="Imagesrc()" />
        <br />
        <asp:Button ID="btnPost" runat="server"
            Text="上传" OnClick="btnPost_Click" /></div>
    </form>
</body>

defualt.aspx.cs代码
view plaincopy to clipboardprint
代码如下:

protected void btnPost_Click(object sender, EventArgs e) 
   { 
       string PostName = Server.MapPath("Image"); 
       string fileName = FileUpload1.FileName; 
       //是否包含此文件 
       if (FileUpload1.HasFile) 
       { 
           FileUpload1.SaveAs(PostName "/" fileName);            
       } 
   }

Copyright © 2016-2025 www.dzhlxh.cn 金源码 版权所有 Power by

网站模板下载|网络推广|微博营销|seo优化|视频营销|网络营销|微信营销|网站建设|织梦模板|小程序模板