zoukankan
html css js c++ java
上传文件用户控件
代码
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
Admin_UploadFile : System.Web.UI.UserControl
{
private
string
uppaths
=
"
../uploads
"
;
//
必须存在
private
int
uptype
=
2
;
private
int
uplimite
=
100
;
private
string
filetype
=
"
jpg|gif|png|bmp
"
;
private
string
cssclass
=
""
;
private
string
filepath
=
""
;
//
上传路径
public
string
upPaths
{
get
{
return
uppaths; }
set
{ uppaths
=
value; }
}
//
上传类型(1:原文件名 2:日期时间)
public
string
upType
{
get
{
return
uptype.ToString(); }
set
{ uptype
=
Convert.ToInt32(value); }
}
//
限制大小(KB)
public
string
upLimite
{
get
{
return
uplimite.ToString(); }
set
{ uplimite
=
Convert.ToInt32(value);}
}
//
可上传文件类型(扩展名)
public
string
fileType
{
get
{
return
filetype; }
set
{ filetype
=
value; }
}
public
string
CssClass
{
get
{
return
cssclass; }
set
{ cssclass
=
value; }
}
public
string
filePath
{
get
{
return
PicPath.Text; }
set
{
filepath
=
value;
PicPath.Text
=
filepath;
}
}
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(
!
IsPostBack)
{
UploadBox.CssClass
=
cssclass;
}
}
protected
void
Button1_Click(
object
sender, EventArgs e)
{
string
fullname;
fullname
=
FileUpload1.FileName.ToString();
string
url
=
FileUpload1.PostedFile.FileName.ToString();
//
这个是以前2003用的,先取得全部的上传文件路径个名字,然后再利用SubString方法来得到用户名,现在看来是没有必要了
string
typ
=
FileUpload1.PostedFile.ContentType.ToString();
//
获取文件MIME内容类型
string
typ2
=
fullname.Substring(fullname.LastIndexOf(
"
.
"
)
+
1
);
//
获取文件名字 . 后面的字符作为文件类型
long
size
=
FileUpload1.PostedFile.ContentLength
/
1024
;
int
i
=
0
;
if
(uptype
!=
1
)
{
fullname
=
System.DateTime.Now.ToString(
"
yyyyMMddhhmmss
"
)
+
"
.
"
+
typ2;
}
string
[] sArray
=
filetype.Split(
'
|
'
);
foreach
(
string
s
in
sArray)
{
if
(s
==
typ2)
{
i
=
i
+
1
;
}
}
if
(i
>
0
)
{
if
(uplimite
>=
size)
{
FileUpload1.SaveAs(Server.MapPath(uppaths)
+
"
\\
"
+
fullname);
//
将文件保存在跟目录的UP文件夹下
PicPath.Text
=
uppaths
+
@"
/
"
+
fullname;
Utility.jsUtility.Alert(
"
上传成功!
"
);
}
else
{
Utility.jsUtility.Alert(
"
您上传的文件不能超过
"
+
uplimite.ToString()
+
"
KB!
"
);
}
}
else
{
Utility.jsUtility.Alert(
"
文件类型错误!支持类型:
"
+
filetype);
}
}
}
界面
<%
@ Control Language
=
"
C#
"
AutoEventWireup
=
"
true
"
CodeFile
=
"
UploadFile.ascx.cs
"
Inherits
=
"
Admin_UploadFile
"
%>
<
asp:Panel ID
=
"
UploadBox
"
runat
=
"
server
"
>
上传图片:
<
asp:FileUpload ID
=
"
FileUpload1
"
runat
=
"
server
"
/>&
nbsp;
<
asp:Button ID
=
"
Button1
"
runat
=
"
server
"
Text
=
"
开始上传
"
OnClick
=
"
Button1_Click
"
/>
<
br
/>
图片路径:
<
asp:TextBox ID
=
"
PicPath
"
runat
=
"
server
"
Width
=
"
280px
"
/>
</
asp:Panel
>
查看全文
相关阅读:
LinQ 语法基础
JQuery 补充
JQuery Ajax 获取数据
JQuery Ajax
jQuery 动画
Python+Spark2.0+hadoop学习笔记——Python Spark MLlib Decision Tree MultiClassification多分类
Python+Spark2.0+hadoop学习笔记——Python Spark MLlib Naive Bayes二分类
Python+Spark2.0+hadoop学习笔记——Python Spark MLlib支持向量机二分类
Python+Spark2.0+hadoop学习笔记——Python Spark MLlib逻辑斯蒂回归二分类
Python+Spark2.0+hadoop学习笔记——Python Spark MLlib决策树二分类
原文地址:https://www.cnblogs.com/yeagen/p/1332134.html
最新文章
《C/C++工程师综合练习卷》之小试牛刀
《编程珠玑》阅读小记(3) — 数据决定数据结构
《编程珠玑》阅读小记(1)— 开篇
菜鸟的《Linux程序设计》学习—shell script
LeetCode(3)Longest Substring Without Repeating Characters
Memcached 之增删改查命令
c# 验证码实现代码
c# cookie帮助类
js手机移动端选择插件 mobileSelect.js
Mysql 之实现多字段模糊查询
热门文章
redis与其可视化工具在win7上的安装
c# md5加密封装
js判断数组中是否包含某个值
PHP实现几秒前、几分钟前、几小时前、几天前
微信jssdk图片上传
LinQ to SQL 增,删,改 代码演示
LINQ to SQL 增,删,改
LinQ to SQL 查询
LinQ To DataSet
LinQ To Object
Copyright © 2011-2022 走看看