asp.net实现上传文件显示本地绝对路径的实例代码
程序员文章站
2024-03-31 16:44:46
页面代码主要就是jsview plaincopy to clipboardprint复制代码 代码如下: ...
页面代码主要就是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);
}
}
上一篇: XHTML标准语法
下一篇: Java——对象初始化顺序使用详解