文件上传
来源:互联网 发布:查询自己电脑端口 编辑:程序博客网 时间:2024/05/01 21:27
if (this.myFile.PostedFile != null)
{
string photoName1 = myFile.PostedFile.FileName; //获取初始文件名
int i = photoName1.LastIndexOf("."); //取得文件名中最后一个"."的索引
string newext = photoName1.Substring(i); //获取文件扩展名
if (newext != ".gif" && newext != ".jpg"&&newext!=".jpeg" && newext != ".bmp" && newext != ".png")
{
Response.Write("文件格式不正确!");
Response.End();
}
DateTime now = DateTime.Now; //获取系统时间
string photoName2 = now.Millisecond.ToString() + "_" + myFile.PostedFile.ContentLength.ToString() + newext; //重新为文件命名,时间毫秒部分+文件大小+扩展名
string sql = Server.MapPath("photos//" + photoName2);
myFile.PostedFile.SaveAs(sql); // 保存文件到路径,用Server.MapPath()取当前文件的绝对目录.在asp.net里"/"必须用""代替
this.Image1.ImageUrl = "photos/" + photoName2;
}
{
string photoName1 = myFile.PostedFile.FileName; //获取初始文件名
int i = photoName1.LastIndexOf("."); //取得文件名中最后一个"."的索引
string newext = photoName1.Substring(i); //获取文件扩展名
if (newext != ".gif" && newext != ".jpg"&&newext!=".jpeg" && newext != ".bmp" && newext != ".png")
{
Response.Write("文件格式不正确!");
Response.End();
}
DateTime now = DateTime.Now; //获取系统时间
string photoName2 = now.Millisecond.ToString() + "_" + myFile.PostedFile.ContentLength.ToString() + newext; //重新为文件命名,时间毫秒部分+文件大小+扩展名
string sql = Server.MapPath("photos//" + photoName2);
myFile.PostedFile.SaveAs(sql); // 保存文件到路径,用Server.MapPath()取当前文件的绝对目录.在asp.net里"/"必须用""代替
this.Image1.ImageUrl = "photos/" + photoName2;
}
- 文件上传---文件上传
- 上传文件
- 文件上传
- 上传文件
- 文件上传
- 文件上传
- 上传文件
- 上传文件
- 文件上传
- 文件上传
- 文件上传
- 文件上传
- 文件上传
- 文件上传
- 文件上传
- 上传文件
- 文件上传
- 文件上传
- Linux Administration: A Beginner's Guide, Fifth Edition
- 在Win32平台中,多读单写锁如何实现?
- AJAX: A Beginner's Guide
- 坚持是件很不容易的事情
- 网站优化的作业..
- 文件上传
- 学习。
- 03/30/09
- 无法找到 secchk.lib ,移植 evc 到 2005
- java中一个关于倒序链表的小程序
- 下载
- iis 运行asp.net配置
- 用C++实现对回文的判断
- NTFS