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网站文件上传下载功能的更多相关文章

  1. JavaWeb实现文件上传下载功能实例解析

    转:http://www.cnblogs.com/xdp-gacl/p/4200090.html JavaWeb实现文件上传下载功能实例解析 在Web应用系统开发中,文件上传和下载功能是非常常用的功能 ...

  2. JavaWeb实现文件上传下载功能实例解析 (好用)

    转: JavaWeb实现文件上传下载功能实例解析 转:http://www.cnblogs.com/xdp-gacl/p/4200090.html JavaWeb实现文件上传下载功能实例解析 在Web ...

  3. WEB文件上传下载功能

    WEB文件上传下载在日常工作中经常用到的功能 这里用到JS库 http://files.cnblogs.com/meilibao/ajaxupload.3.5.js 上传代码段(HTML) <% ...

  4. Struts2实现文件上传下载功能(批量上传)

    今天来发布一个使用Struts2上传下载的项目, struts2为文件上传下载提供了好的实现机制, 首先,可以先看一下我的项目截图 关于需要使用的jar包,需要用到commons-fileupload ...

  5. C# 文件上传下载功能实现 文件管理引擎开发

    Prepare 本文将使用一个NuGet公开的组件技术来实现一个服务器端的文件管理引擎,提供了一些简单的API,来方便的实现文件引擎来对您自己的软件系统的文件进行管理. 在Visual Studio ...

  6. php实现文件上传下载功能小结

    文件的上传与下载是项目中必不可少的模块,也是php最基础的模块之一,大多数php框架中都封装了关于上传和下载的功能,不过对于原生的上传下载还是需要了解一下的.基本思路是通过form表单post方式实现 ...

  7. 文件一键上传、汉字转拼音、excel文件上传下载功能模块的实现

    ----------------------------------------------------------------------------------------------[版权申明: ...

  8. javaweb项目中的文件上传下载功能的实现

    框架是基于spring+myBatis的. 前台页面的部分代码: <form action="${ctx}/file/upLoadFile.do"method="p ...

  9. FasfDFS整合Java实现文件上传下载功能实例详解

    https://www.jb51.net/article/120675.htm 在上篇文章给大家介绍了FastDFS安装和配置整合Nginx-1.13.3的方法,大家可以点击查看下. 今天使用Java ...

随机推荐

  1. HTML5 Media事件

    Media 事件 由媒介(比如视频.图像和音频)触发的事件(适用于所有 HTML 元素,但常见于媒介元素中,比如 <audio>.<embed>.<img>.< ...

  2. 安装Visual Studio 2010时提示"The location specified for the help content store is invalid or you do not have access to it".

    运行注册表: (运行->输入"regedit").在 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Help\v1.0中,删除"Loc ...

  3. rdlc报表

    也是第一次接触报表这个东西.现在在我理解,报表无非就是两个内容,格式和数据. 格式没有多少了解,就记录了,以后再续.数据的绑定和结果的显示是怎么实现的呢? 今天的主角就是rdlc这个文件和Report ...

  4. JavaScript HTML DOM - 改变 HTML

    JavaScript HTML DOM - 改变 HTML HTML DOM 允许 JavaScript 改变 HTML 元素的内容. 改变 HTML 输出流 JavaScript 能够创建动态的 H ...

  5. C蛮的全栈之路-序章 技术栈选择与全栈工程师

    目录 C蛮的全栈之路-序章 技术栈选择与全栈工程师C蛮的全栈之路-node篇(一) 环境布置C蛮的全栈之路-node篇(二) 实战一:自动发博客 博主背景 985院校毕业,至今十年C++开发工作经验, ...

  6. spring jdbctemplate调用procedure(返回游标)

    package cn.com.git.htsc.uac.core.repository.report; import cn.com.git.htsc.uac.core.api.dto.report.R ...

  7. Java学习----this和super(在继承中)

    public class Base { /*public Base() { System.out.println("Base 类的初始构造方法"); }*/ public Base ...

  8. java 下载文件 内容为空。

    检查下是不是io流没有关闭,记得关闭所有流.

  9. MySql数据库3【优化1】表的优化

    一.表结构的优化 1.标准化  标准化是在数据库中组织数据的过程.其中包括,根据设计规则创建表并在这些表间建立关系:通过取消冗余度与不一致相关性,该设计规则可以同时保护数据并提高数据的灵活性.通常数据 ...

  10. Python学习的一些好资料

    教程: 1. 廖雪峰的Python教程:http://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a0 ...