protected void Button10_Click(object sender, EventArgs e)
    {
        string name = FileUpload1.FileName;//获取文件名
        string name1 = FileUpload1.PostedFile.FileName; //获取完整客户端文件路径
        string type = FileUpload1.PostedFile.ContentType;//上传文件类型
        string size = FileUpload1.PostedFile.ContentLength.ToString();//上传文件大小
        string type2 = name.Substring(name.LastIndexOf(".") + 1);//上传文件后缀名
        string ipath = Server.MapPath("upload") + "\\" + name; //上传到服务器上后的路径(实际路径),"\\"必须为两个斜杠,在C#中一个斜杠表示转义符.
        string ipath1 = Server.MapPath("upload");//创建文件夹时用
        string wpath = "upload\\" + name; //虚拟路径
        if (type2 == "jpg" || type2 == "gif" || type2 == "bmp" || type2 == "png")//根据后缀名来限制上传类型
        {
            
            if (!System.IO.Directory.Exists(ipath1))//判断文件夹是否已经存在
            {
                System.IO.Directory.CreateDirectory(ipath1);//创建文件夹
            } 
            FileUpload1.SaveAs(ipath);//上传文件到ipath这个路径里
            
        }
    }

相关文章:

  • 2022-12-23
  • 2021-09-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-25
  • 2022-12-23
相关资源
相似解决方案