关闭

上传保存

681人阅读 评论(0) 收藏 举报

 private void Button2_Click(object sender, System.EventArgs e)
  {
   string fullName = File1.PostedFile.FileName.ToString();
   //string fileName = fullName.Substring(fullName.LastIndexOf("//")+1);

   string extendName = fullName.Substring(fullName.LastIndexOf(".")+1).Trim().ToLower();

   if(extendName == "jpg" || extendName == "gif" || extendName =="swf")
   {
    string dateName = serverFileName();
    string dateUpName = "//"+dateName+ "." + extendName;

    this.File1.PostedFile.SaveAs(Server.MapPath("upFile")+dateUpName);
    Response.Write("上传成功!");
    this.ImageButton1.ImageUrl = "upFile" +dateUpName;
   }
   else
   {
    Response.Write("格式不对");
   }

  }

  public string serverFileName()
  {
   string dateFileName = System.DateTime.Now.ToUniversalTime().ToString();   
   dateFileName=dateFileName.Replace("-","");
   dateFileName =dateFileName.Replace(":","");
   dateFileName =dateFileName.Replace(" ","");
   //Response.Write(dateFileName);
   return dateFileName;
  }

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1372499次
    • 积分:19851
    • 等级:
    • 排名:第411名
    • 原创:448篇
    • 转载:1067篇
    • 译文:4篇
    • 评论:143条
    文章存档
    最新评论