首页 > 编程 > .NET > 正文

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

2024-07-10 13:15:50
字体:
来源:转载
供稿:网友
页面代码主要就是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 runat="server">
    <div>
    <img onchange="Imagesrc()" />
        <br />
        <asp:Button runat="server"
            Text="上传" /></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 runat="server">
    <div>
    <img onchange="Imagesrc()" />
        <br />
        <asp:Button runat="server"
            Text="上传" /></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);            
       } 
   }

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