protected void Button1_Click(object sender, EventArgs e)
{ if (Directory.Exists(Server.MapPath("~/upimg/hufu")) == false)//如果不存在就创建file文件夹
{
Directory.CreateDirectory(Server.MapPath("~/upimg/hufu"));
} //Directory.Delete(Server.MapPath("~/upimg/hufu"), true);//删除文件夹以及文件夹中的子目录,文件 //判断文件的存在 if (File.Exists(Server.MapPath("~/upimg/Data.html")))
{
Response.Write("Yes"); //存在文件 } else
{
Response.Write("No");
//不存在文件
File.Create(MapPath("~/upimg/Data.html"));//创建该文件 } string name = GetFiles.FileName;//获取已上传文件的名字
string size = GetFiles.PostedFile.ContentLength.ToString();//获取已上传文件的大小
string type = GetFiles.PostedFile.ContentType;//获取已上传文件的MIME
string postfix = name.Substring(name.LastIndexOf(".") + 1);//获取已上传文件的后缀
string ipath = Server.MapPath("upimg") +"\\"+ name;//获取文件的实际路径
string fpath = Server.MapPath("upfile") + "\\" + name;
string dpath = "upimg\\" + name;//判断写入数据库的虚拟路径 ShowPic.Visible = true;//激活
ShowText.Visible = true;//激活 //判断文件格式
if (name == "") {
Response.Write("<script>alert('上传文件不能为空')</script>");
} else{ if (postfix == "jpg" || postfix == "gif" || postfix == "bmp" || postfix == "png")
{
GetFiles.SaveAs(ipath);
ShowPic.ImageUrl = dpath;
ShowText.Text = "你上传的图片名称是:" + name + "<br>" + "文件大小:" + size + "KB" + "<br>" + "文件类型:" + type + "<br>" + "存放的实际路径为:" + ipath; } else
{
ShowPic.Visible = false;//隐藏图片
GetFiles.SaveAs(fpath);//由于不是图片文件,因此转存在upfile这个文件夹
ShowText.Text = "你上传的文件名称是:" + name + "<br>" + "文件大小:" + size + "KB" + "<br>" + "文件类型:" + type + "<br>" + "存放的实际路径为:" + fpath; }
 
http://www.cnblogs.com/szytwo/archive/2012/03/22/2411703.html

最新文章

  1. Ubuntu Server(Ubuntu 14.04 LTS 64位)安装libgdiplus2.10.9出错问题记录
  2. Xcode相关整理
  3. 微软职位内部推荐-Service Engineer II for Azure Cloud Network
  4. linux下nagios的安装与部署
  5. jQuery 自学笔记—5 遍历
  6. Codeforces Round #246 (Div. 2) D. Prefixes and Suffixes(后缀数组orKMP)
  7. DLL and LIB
  8. 在使用pydelicious时出现HTTP Error 500: Internal Server Error的错误的解决方法:
  9. Unity Socket TCP
  10. Arduino传感器学习目录
  11. union: apt command
  12. Linux系统学习之正则表达式
  13. 51nod1185 威佐夫游戏 V2 (模拟乘法)
  14. FTP上传、下载(简单小例子)
  15. Django框架----ORM数据库操作注意事项
  16. Ubuntu 14.04 上安装 Gurobi
  17. Python json模块dumps loads
  18. js如何判断IE浏览器的版本包括IE11
  19. Sublime Text3编辑器简介
  20. Python str 与 bytes 类型 之间的转换

热门文章

  1. 20145210实验五《Java网络编程》
  2. array_count_values函数
  3. [转]BEHAVOUR TREE2
  4. What Controls are new for windows phone 8.1
  5. magento和discuz(ucenter)整合集成开发思路
  6. magento的robots文件编写和判断是否是一个导航分类页面
  7. 【ajax】xhr
  8. 彻底弄懂css中单位px和em,rem的区别 转的自己看
  9. yii点击上传图片后立即显示
  10. 【转】beancopy的替代方案