runxinzhi.com
首页
百度搜索
asp.net文件上传
1.html
<
html
xmlns
="http://www.w3.org/1999/xhtml"
>
<
head
runat
="server"
>
<
title
>
无标题页
</
title
>
</
head
>
<
body
>
<
form
id
="form1"
runat
="server"
>
<
div
>
单文件上传
<
br
/>
<
br
/>
<
input
id
="File1"
runat
="server"
type
="file"
/>
<
br
/>
<
asp:Button
ID
="Button1"
runat
="server"
OnClick
="Button1_Click"
Text
="Button"
/>
<
br
/>
<
asp:Label
ID
="LblMsg"
runat
="server"
Height
="256px"
Width
="100%"
></
asp:Label
>
</
div
>
</
form
>
</
body
>
</
html
>
2.cs
using
System;
using
System.Data;
using
System.Configuration;
using
System.Collections;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Web.UI.HtmlControls;
public
partial
class
other_ShangChuan1 : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(
!
IsPostBack)
{ }
}
protected
void
Button1_Click(
object
sender, EventArgs e)
{
if
(File1.PostedFile.FileName
!=
""
)
{
//
上传文件的绝对路径 如:C:\12.jpg
string
sFile
=
File1.PostedFile.FileName;
//
获取文件全名 例:12.jpg
sFile
=
sFile.Substring(sFile.LastIndexOf(
"
\\
"
)
+
1
);
//
获取后缀名 例 .jpg
sFile
=
sFile.Substring(sFile.LastIndexOf(
"
.
"
));
//
为了防止重名,获得日期为文件名 年月日时分秒毫秒
string
datatime
=
System.DateTime.Now.ToString(
"
yyyMMddHHmmssffff
"
);
//
上传后文件的新名
sFile
=
datatime
+
sFile;
//
AppDomain.CurrentDomain.BaseDirectory.ToString() 获取此项目的根目录
//
sPath 获取上传后的路径
string
sPath
=
AppDomain.CurrentDomain.BaseDirectory.ToString()
+
"
uploads\\
"
+
sFile;
//
上传文件
File1.PostedFile.SaveAs(sPath);
this
.LblMsg.Text
=
"
文件已经上传到:
"
+
sPath;
this
.LblMsg.Text
+=
"
<br/>上传文件名称:
"
+
this
.File1.PostedFile.FileName;
this
.LblMsg.Text
+=
"
<br/>上传文件类型:
"
+
this
.File1.PostedFile.ContentType;
this
.LblMsg.Text
+=
"
<br/>上传文件大小:
"
+
this
.File1.PostedFile.ContentLength
+
"
Byte
"
;
}
else
{
this
.LblMsg.Text
=
"
请选择需要上传的文件?
"
;
}
}
}
相关阅读:
性能相差7千倍的ToString方法
重构打造爱因斯坦谜题最快算法
Windows Phone 7将胜出的五条论据
让火狐狸遨游起来
What's your understanding about RIA?
[English Practise]Action when meeting a problem at work
linux socket编程
nginx服务器的配置
要搬到csdn了
搭建一个全栈式的HTML5移动应用框架
原文地址:https://www.cnblogs.com/puke/p/782513.html
最新文章
使用spdevelop进行数据库建模
winxp sp2安装IE7
使用WebDeployment Project改善VS2005发布网站问题 (二) 视频演示
MySQL 存储过程中的循环操作
MSN中文网改版
诺顿误杀导致系统崩溃 百万PC面临灾难
使用AjaxPro实现ajax效果
[转载翻译][重新整理]西川善司的”METAL GEAR SOLID 4”图形讲座(2)
[转载翻译][重新整理]西川善司的”METAL GEAR SOLID 4”图形讲座(4)
盖茨与巴菲特
热门文章
[转载翻译][重新整理]西川善司的”METAL GEAR SOLID 4”图形讲座(3)
「逆転裁判」の実写映画化が決定 主演・成歩堂龍一役は成宮寛貴さん!
网曝最牛点餐方式:顾客人手一个iPad
[转载翻译][重新整理]西川善司的”METAL GEAR SOLID 4”图形讲座(5)
[转载翻译] 西川善司3D游戏技术系列【LOST PLANET2】图形讲座
[转载翻译][重新整理]西川善司的”METAL GEAR SOLID 4”图形讲座(1)
.Net 4.0并行库实用性演练
.Net 4.0并行库实用性演练(续)
爱因斯坦智力题算法的分析
.Net 4.0并行库实用性演练(前言)
Copyright © 2020-2023
润新知