#region 上传文件到服务器 /// <summary> /// 上传文件到服务器 /// </summary> /// <param name="str_path">需要存放到服务器上的路径</param> /// <param name="file1">客户端文件</param> /// <returns>上传是否成功</returns> public static string UpFile(string str_path, HttpPostedFile file1, out string v_err) { v_err = null; string aaa = file1.FileName; if (Directory.Exists(str_path) == false) { Directory.CreateDirectory(str_path); } char[] a ={ '\\' }; string file_name = Guid.NewGuid().ToString("n")+file1.FileName.Split(a)[file1.FileName.Split(a).Length - 1]; if (file_name == "") { str_path = ""; v_err = "客户端文件不存在!"; return null; } else { str_path = str_path + "\\" + file_name; file1.SaveAs(str_path); return file_name; } } #endregion
来源:https://www.cnblogs.com/zengxh/p/12390699.html