其他分享
首页 > 其他分享> > 上传文件帮助类

上传文件帮助类

作者:互联网

/// <summary>
	/// 文件上传帮助类
	/// </summary>
	public class UploadHelper
	{
		/// <summary>
		/// 附件上传 成功:succeed、失败:error、文件太大:-1、
		/// </summary>
		/// <param name="file">单独文件的访问</param>
		/// <param name="path">存储路径</param>
		/// <param name="filename">输出文件名</param>
		/// <returns></returns>
		public static string FileUpload(HttpPostedFileBase file, string path, string filename)
		{
			bool flag = !Directory.Exists(path);
			if (flag)
			{
				Directory.CreateDirectory(path);
			}
			string result;
			try
			{
				int num = file.ContentLength / 1024 / 1024;
				bool flag2 = num > 10;
				if (flag2)
				{
					result = "-1";
				}
				else
				{
					file.SaveAs(path + filename);
					result = "succeed";
				}
			}
			catch (Exception ex)
			{
				result = ex.Message;
			}
			return result;
		}
	}

标签:文件,string,帮助,result,file,path,上传
来源: https://www.cnblogs.com/wml-it/p/16522509.html