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这个路径里
C# 文件上传,并创建文件夹
最新推荐文章于 2024-05-06 22:23:44 发布