public static byte[] GetBinaryFile(TransferFileInfo fileInfo) { try { if (File.Exists(fileInfo.FileName)) { byte[] buffer = null; using (FileStream fs = new FileStream(fileInfo.FileName, FileMode.Open, FileAccess.Read)) { fs.Seek(fileInfo.FilePosition, SeekOrigin.Begin); buffer = new byte[fileInfo.FileBufferLength]; fs.Read(buffer, 0, buffer.Length); } return(buffer); } } catch (Exception ex) { } return(null); }
public static TransferFileInfo PushBinaryFileInfo(TransferFileInfo fileInfo, byte[] binary) { string foldername = fileInfo.FolderName; string filename = fileInfo.FileName; string attachid = Path.GetFileNameWithoutExtension(filename); foldername = foldername.Replace("/", "\\"); string diskPath = foldername; //todo if (!Directory.Exists(diskPath)) { Directory.CreateDirectory(diskPath); } string filePath = diskPath + "\\" + fileInfo.FileName; using (FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { fs.Seek(fileInfo.FilePosition, SeekOrigin.Begin); fs.Write(binary, 0, fileInfo.FileBufferLength); long fslength = fs.Length; fs.Flush(); } return(fileInfo); }