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>");
} 我自己写的源代码你自己慢慢研究吧
相关文章
- 12-18简单的实现文件上传下载功能
- 12-18Asp.Net 生成网站时不生成.pdb文件
- 12-18minio实现文件上传下载和删除功能
- 12-18基于.NET6平台开发WebApi(十二)—— 添加文件上传下载功能
- 12-18基于.NET6平台开发WebApi(十二)—— 添加文件上传下载功能
- 12-18asp.net实现将网页存为mht格式文件,类似于网页另存为mht功能
- 12-18JavaWeb实现文件上传下载功能实例解析
- 12-18在ASP.NET中实现压缩多个文件为.zip文件,实现批量下载功能 (转载并优化处理篇)
- 12-18部署在IIS服务器的asp.net 网站,禁止访问指定类型文件
- 12-18iis部署网站后出现未能写入输出文件“c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\106f9ae8\cc0e1