没有合适的资源?快使用搜索试试~ 我知道了~
ASP.NET上传文件的源码,最简单的上传文件的方法
资源推荐
资源详情
资源评论
if (FileUpload1.HasFile)
{
string fileContentType = FileUpload1.PostedFile.ContentType;
if (fileContentType == "image/bmp" || fileContentType == "image/gif" || fileContentType == "image/pjpeg" || fileContentType == "image/jpeg")
{
string name = FileUpload1.PostedFile.FileName;
FileInfo file = new FileInfo(name);
string filename = file.Name;
string webFilePath = Server.MapPath("image/" + filename);
if (!File.Exists(webFilePath))
{
try
{
FileUpload1.SaveAs(webFilePath);
this.Label2.Text = "提示:文件“" + filename + "”上传成功!";
this.Label4.Text = "image/" + filename;
this.Image1.ImageUrl = "image/" + filename;
}
catch (Exception ex)
{
this.Label2.Text = "提示:文件上传失败,原因是:" + ex.Message;
}
}
else
{
this.Label2.Text = "提示:文件已经存在,请重命名后上传!";
}
}
else
{
string fileContentType = FileUpload1.PostedFile.ContentType;
if (fileContentType == "image/bmp" || fileContentType == "image/gif" || fileContentType == "image/pjpeg" || fileContentType == "image/jpeg")
{
string name = FileUpload1.PostedFile.FileName;
FileInfo file = new FileInfo(name);
string filename = file.Name;
string webFilePath = Server.MapPath("image/" + filename);
if (!File.Exists(webFilePath))
{
try
{
FileUpload1.SaveAs(webFilePath);
this.Label2.Text = "提示:文件“" + filename + "”上传成功!";
this.Label4.Text = "image/" + filename;
this.Image1.ImageUrl = "image/" + filename;
}
catch (Exception ex)
{
this.Label2.Text = "提示:文件上传失败,原因是:" + ex.Message;
}
}
else
{
this.Label2.Text = "提示:文件已经存在,请重命名后上传!";
}
}
else
资源评论
「已注销」
- 粉丝: 0
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功