c# post 接收传来的文件

private void UploadFile()
    {
      //
      //......其他代码
      //
      HttpFileCollection files = HttpContext.Current.Request.Files;
      if(files.Count>0)
      {
        int lintTemp = files[0].FileName.LastIndexOf(".");//得到input标签中的file文件路径;
        string lstrFileType = string.Empty;
        string lstrContentType = string.Empty;
        if(lintTemp!=-1 &&files[0].FileName.Length>lintTemp+1)
        {
          lstrFileType = files[0].FileName.Substring(lintTemp+1).ToUpper();
        }
        if(lstrFileType.ToUpper()=="JPG")
        {
          if(files[0].ContentLength<10485760)
          {
           //记得要先保存到应用程序发布所在的服务器上!
            files[0].SaveAs(Server.MapPath("~/Files/")+"JPG1."+files[0].FileName.Substring(files[0].FileName.LastIndexOf(".")));
          }
        }
      }
      //
      //......其他代码
      //
    }

 

猜你喜欢

转载自www.cnblogs.com/qqhfeng/p/10628588.html
今日推荐