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

时间:2022-09-18 00:10:29

页面代码主要就是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 /> 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);             
       }  
   }