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网站文件上传下载功能,布布扣,bubuko.com

ASP.NET网站文件上传下载功能

上一篇:Ubuntu如何配置Telnet服务器


下一篇:sublime配置开发nodejs