ASP.NET网站文件上传下载功能
if (!IsPostBack)
{
if (Application["RaNum"] == null)
{
Random ra = new Random();
Application["RaNum"] = ra;
}
}
if (pictureUP.HasFile)
{
//Response.Write(FileUpload1.PostedFile.ContentLength);
if (pictureUP.PostedFile.ContentLength < 200 * 1024)
{
//string strPath = Server.MapPath("~/uploadfiles/");
//FileUpload1.SaveAs(strPath+FileUpload1.FileName);
string[] strs = pictureUP.FileName.Split(new char[] { '.' });
string strExt = strs[strs.Length - 1].ToLower();
ArrayList list = new ArrayList();
list.Add("jpg");
list.Add("gif");
list.Add("bmp");
if (list.Contains(strExt))
{
ArrayList listType = new ArrayList();
listType.Add("image/pjpeg");
// TextBox1.Text=pictureUP.PostedFile.ContentType;
listType.Add("image/gif");
listType.Add("image/bmp");
if (listType.Contains(pictureUP.PostedFile.ContentType))
{
Random ra = (Random)Application["RaNum"];
int strRa = ra.Next();
Int64 strDate = Convert.ToInt64(DateTime.Now.ToString("yyyyMMddhhmmss"));
string FileName = strDate.ToString("X") + strRa.ToString("X") + pictureUP.FileName;
string strPath = Server.MapPath("~/images/user/");
string strFilePath = strPath + FileName;
// TextBox1.Text = strFilePath;
while (File.Exists(strFilePath))
{
strRa = ra.Next();
strDate = Convert.ToInt64(DateTime.Now.ToString("yyyyMMddhhmmss"));
FileName = strDate.ToString("X") + strRa.ToString("X") + pictureUP.FileName;
strFilePath = strPath + FileName; }
try
{
pictureUP.SaveAs(strFilePath);
// Response.Write("上传成功!");
userInfoUpData U_Info = new userInfoUpData();
U_Info.UserID = userID.Text;
U_Info.UserPwd = userPWD.Text;
U_Info.UserName = userName.Text;
U_Info.UserSex = userSex.Text;
U_Info.UserAge = Convert.ToInt32(userAge.Text);
U_Info.UserTell = userTell.Text;
U_Info.UserAdr = userAdrr.Text;
U_Info.UserPic = FileName;
UserBLL U_Info_Bll = new UserBLL();
if (U_Info_Bll.UserInfoUp(U_Info) > 0)
{ Response.Write("<script>alert('修改成功')</script>");
}
else
{
Response.Write("<script>alert('修改失败')</script>");
}
}
catch
{
Response.Write("上传失败!");
}
}
}
else
{
Response.Write("<script>alert('上传的文件类型错误!')</script>");
}
}
else
{
Response.Write("<script>alert('上传文件的大小超过了200k!')</script>");
}
}
else
{
Response.Write("<script>alert('请选择一个上传的文件!')</script>");
} 我自己写的源代码你自己慢慢研究吧
ASP.NET网站文件上传下载功能的更多相关文章
- JavaWeb实现文件上传下载功能实例解析
转:http://www.cnblogs.com/xdp-gacl/p/4200090.html JavaWeb实现文件上传下载功能实例解析 在Web应用系统开发中,文件上传和下载功能是非常常用的功能 ...
- JavaWeb实现文件上传下载功能实例解析 (好用)
转: JavaWeb实现文件上传下载功能实例解析 转:http://www.cnblogs.com/xdp-gacl/p/4200090.html JavaWeb实现文件上传下载功能实例解析 在Web ...
- WEB文件上传下载功能
WEB文件上传下载在日常工作中经常用到的功能 这里用到JS库 http://files.cnblogs.com/meilibao/ajaxupload.3.5.js 上传代码段(HTML) <% ...
- Struts2实现文件上传下载功能(批量上传)
今天来发布一个使用Struts2上传下载的项目, struts2为文件上传下载提供了好的实现机制, 首先,可以先看一下我的项目截图 关于需要使用的jar包,需要用到commons-fileupload ...
- C# 文件上传下载功能实现 文件管理引擎开发
Prepare 本文将使用一个NuGet公开的组件技术来实现一个服务器端的文件管理引擎,提供了一些简单的API,来方便的实现文件引擎来对您自己的软件系统的文件进行管理. 在Visual Studio ...
- php实现文件上传下载功能小结
文件的上传与下载是项目中必不可少的模块,也是php最基础的模块之一,大多数php框架中都封装了关于上传和下载的功能,不过对于原生的上传下载还是需要了解一下的.基本思路是通过form表单post方式实现 ...
- 文件一键上传、汉字转拼音、excel文件上传下载功能模块的实现
----------------------------------------------------------------------------------------------[版权申明: ...
- javaweb项目中的文件上传下载功能的实现
框架是基于spring+myBatis的. 前台页面的部分代码: <form action="${ctx}/file/upLoadFile.do"method="p ...
- FasfDFS整合Java实现文件上传下载功能实例详解
https://www.jb51.net/article/120675.htm 在上篇文章给大家介绍了FastDFS安装和配置整合Nginx-1.13.3的方法,大家可以点击查看下. 今天使用Java ...
随机推荐
- 用Javascript进行HTML转义(分享)
众所周知页面上的字符内容通常都需要进行HTML转义才能正确显示,尤其对于Input,Textarea提交的内容,更是要进行转义以防止javascript注入攻击. 通常的HTML转义主要是针对 ...
- 23、Javascript DOM
DOM Document Object Model(文档对象模型)定义了html和xml的文档标准. DOM 节点树 <html> <head> <title>DO ...
- CSS3新增Hsl、Hsla、Rgba色彩模式以及透明属性(转)
CSS2中色彩模式只有RGB色彩模式(RGB即RED.Green.BLue)和十六进制(Hex)模式,为了能支持 透明opacity 的Alpha值,CSS3又增加了RGBA色彩模式(RGBA即RED ...
- oracle - 创建数据库
在服务器端的oracle,用户有点差异,当 我通过 'sqlplus / as sysdba' 命令登陆后,并不能创建数据库,sysdba拥有最高的系统权限,登陆后是 sys,以as sysdba登录 ...
- Java线程(学习整理)--2---加入另一个线程join
1.join简介: 今天刚学的,这里我简单总结一下,join本身就是“加入”的意思,那么在线程中是什么意思呢?是在一个线程的run方法执行过程中,当特殊情况下需要执行一些其他的操作的时候,我们会用到j ...
- Vijos1825 NOI2008 志愿者招募 费用流
Orz ByVoid大神的题解:https://www.byvoid.com/blog/noi-2008-employee/ 学习网络流建图的好题,不难想到线性规划的模型,不过利用模型的特殊性,结合网 ...
- C++中extern关键字使用(转)
参考文章:http://blog.csdn.net/sruru/article/details/7951019 chapter1.如何混合编译C语言和C++ 实际开发过程中,C++中会调用C与语言编写 ...
- SGU 112.a^b - b^a
题意: 如标题. 方法: 简单高精度... 代码(继续JAVA 水过) import java.util.*; import java.math.*; public class Solution { ...
- 内置方法+lambda是pythonic的利器
python可以写的非常简洁,通过使用内置的map,reduce,filter,lambda方法,非常具有文艺范. 举个例子,例如 def fromIpToNum(ipAddr): return ...
- 神秘链接__proto__是什么鬼
_proto_实际上是某个实例对象的隐藏属性,而prototype是其构造器函数(或者说‘类’)的原型属性; function Mine() {} var hi = new Function(), ...