using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; using System.IO; using System.Web; namespace BLL { public static class FileStructService { /// /// 获取附件数据流类 /// /// 附件路径 /// public static List GetFileStructByAttachUrl(string attachUrl) { List fileContext = new List(); if (!String.IsNullOrEmpty(attachUrl)) { string filePath = string.Empty; string physicalpath = Funs.localRoot; //HttpContext.Current.Request.PhysicalApplicationPath; filePath = physicalpath + attachUrl; if (File.Exists(filePath)) { FileInfo fileInfo = new FileInfo(filePath); Stream stream = fileInfo.OpenRead(); //读取指定大小的文件流内容到uploadFile.Context以便上传 int b; while (stream.Position > -1 && stream.Position < stream.Length) { if (stream.Length - stream.Position >= 20000000) { b = 20000000; } else { b = (int)(stream.Length - stream.Position); } byte[] filebyte = new byte[b]; stream.Read(filebyte, 0, b); fileContext.Add(filebyte); } stream.Close(); } } return fileContext; } /// /// 获取附件数据流类 多附件的情况 /// /// 附件路径 /// public static List GetMoreFileStructByAttachUrl(string attachUrl) { List fileContext = new List(); if (!String.IsNullOrEmpty(attachUrl)) { string[] strs = attachUrl.Trim().Split(','); foreach (var item in strs) { string filePath = string.Empty; string physicalpath = Funs.localRoot; //HttpContext.Current.Request.PhysicalApplicationPath; filePath = physicalpath + item; if (File.Exists(filePath)) { FileInfo fileInfo = new FileInfo(filePath); if (fileInfo != null) { Stream stream = fileInfo.OpenRead(); if (stream != null) { //读取指定大小的文件流内容到uploadFile.Context以便上传 int b; while (stream.Position > -1 && stream.Position < stream.Length) { if (stream.Length - stream.Position >= 20000000) { b = 20000000; } else { b = (int)(stream.Length - stream.Position); } byte[] filebyte = new byte[b]; stream.Read(filebyte, 0, b); fileContext.Add(filebyte); } } stream.Close(); } } } } return fileContext; } public static byte[][] GetMoreFileArrayStructByAttachUrl(string attachUrl) { List fileContext = new List(); if (!String.IsNullOrEmpty(attachUrl)) { string[] strs = attachUrl.Trim().Split(','); foreach (var item in strs) { string filePath = string.Empty; string physicalpath = Funs.localRoot; //HttpContext.Current.Request.PhysicalApplicationPath; filePath = physicalpath + item; if (File.Exists(filePath)) { FileInfo fileInfo = new FileInfo(filePath); if (fileInfo != null) { Stream stream = fileInfo.OpenRead(); if (stream != null) { //读取指定大小的文件流内容到uploadFile.Context以便上传 int b; while (stream.Position > -1 && stream.Position < stream.Length) { if (stream.Length - stream.Position >= 20000000) { b = 20000000; } else { b = (int)(stream.Length - stream.Position); } byte[] filebyte = new byte[b]; stream.Read(filebyte, 0, b); fileContext.Add(filebyte); } } stream.Close(); } } } } return fileContext.ToArray(); } } }