asp.net实现上传文件显示本地绝对路径的实例代码
作者:
asp.net实现上传图片显示本地绝对路径图片,其实这个还是得用<DIV></DIV>去显示图片会更好一点!用js实现图片的比例压缩让图片一样能够很清楚!下面把代码贴出来
页面代码主要就是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);
}
}
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);
}
}
您可能感兴趣的文章:
- Asp.Net修改上传文件大小限制方法
- Asp.net MVC中使用JQuery插件ajaxFileUpload上传文件
- ASP.NET插件uploadify批量上传文件完整使用教程
- asp.net上传文件到数据库的解决方案
- asp.net中MVC借助Iframe实现无刷新上传文件实例
- asp.net fileupload控件上传文件与多文件上传
- Asp.Net的FileUpload类实现上传文件实例
- Asp.Net模拟表单提交数据和上传文件的实现代码
- 如何限制asp.net中上传文件的大小的代码
- asp.net 模拟提交有文件上传的表单(通过http模拟上传文件)
- 解决.net项目中上传的图片或者文件太大无法上传问题