You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.6 KiB
Plaintext

using System;
using System.Web;
using BP.Difference;
namespace BP.WF.Difference
{
public class WF_File
{
/// <summary>
/// 文件上传
/// </summary>
/// <param name="filePath"></param>
public static void UploadFile(string filePath)
{
try
{
HttpFileCollection filelist = HttpContextHelper.Current.Request.Files;
if (filelist == null || filelist.Count == 0)
{
throw new NotImplementedException("没有上传文件");
}
HttpPostedFile f = filelist[0];
// 写入文件
f.SaveAs(filePath);
}
catch (Exception ex)
{
throw new NotImplementedException(ex.Message);
}
}
/// <summary>
/// 获取文件
/// </summary>
/// <returns></returns>
public static HttpPostedFile GetUploadFile(int index=0)
{
try
{
HttpFileCollection filelist = HttpContextHelper.Current.Request.Files;
if (filelist == null || filelist.Count == 0)
{
throw new NotImplementedException("没有上传文件");
}
return filelist[index];
}
catch (Exception ex)
{
throw new NotImplementedException(ex.Message);
}
}
public static HttpFileCollection GetUploadFiles()
{
try
{
HttpFileCollection filelist = HttpContextHelper.Current.Request.Files;
if (filelist == null || filelist.Count == 0)
{
throw new NotImplementedException("没有上传文件");
}
return filelist;
}
catch (Exception ex)
{
throw new NotImplementedException(ex.Message);
}
}
public static void UploadFile(HttpPostedFile file,string filePath)
{
try
{
// 写入文件
file.SaveAs(filePath);
}
catch (Exception ex)
{
throw new NotImplementedException(ex.Message);
}
}
public static long GetFileLength(HttpPostedFile file)
{
try
{
return file.ContentLength;
}
catch (Exception ex)
{
throw new NotImplementedException(ex.Message);
}
}
}
}