public FileStreamResult ReadFileStreamResult(FileHandle handle) { _MIMEType = "image/jpg";// GetFileMimeType(handle.FileName); FileStreamResult FileStreamResult = null; string FullFilePath = handle.FilePath + @"\" + handle.FileName; if (File.Exists(FullFilePath)) { using (FileStream fileStream = System.IO.File.Open(FullFilePath,FileMode.Open)) { FileStreamResult = new FileStreamResult(fileStream, _MIMEType); } } return FileStreamResult; }
public byte[] ReadFileToByte(FileHandle handle) { string FullFilePath = handle.FilePath + @"\" + handle.FileName; byte[] byteInputStream = null; if (File.Exists(FullFilePath)) { using (FileStream fileStream = System.IO.File.Open(FullFilePath, FileMode.Open)) { // Fill the bytes[] array with the stream data byteInputStream = new byte[fileStream.Length]; fileStream.Read(byteInputStream, 0, (int)byteInputStream.Length); } } return byteInputStream; }
public bool UploadFile(FileHandle handle, ref string retFullFilePath, ref string errorMessage) { if (!string.IsNullOrEmpty(handle.FileName)) { string tempFileName = string.Empty; if(handle.FileName.Contains("\\")) { string arrFileName = handle.FileName.Substring(handle.FileName.LastIndexOf("\\")+1); handle.FileName = arrFileName; } if (handle.Content.Length > 0) { string FileUploadPath = handle.FilePath; Stream filestream = handle.Content; if (!Directory.Exists(handle.FilePath)) { Directory.CreateDirectory(handle.FilePath); } // Create a FileStream object to write a stream to a file string FullFilePath = handle.FilePath + @"\" + handle.FileName; using (FileStream fileStream = System.IO.File.Create(FullFilePath, (int)handle.Content.Length)) { // Fill the bytes[] array with the stream data byte[] byteInputStream = new byte[handle.Content.Length]; handle.Content.Read(byteInputStream, 0, (int)byteInputStream.Length); // Use FileStream object to write to the specified file fileStream.Write(byteInputStream, 0, byteInputStream.Length); } retFullFilePath = FullFilePath; return true; } else { errorMessage = "Error- File should not be empty"; } } else { errorMessage = "Error- No File Name"; } return false; }
public string ReadFileStream( FileHandle handle) { throw new NotImplementedException(); }
public Student SaveExcelFile(Student entity) { string returnErrorMsg = string.Empty; string returnFilePath = string.Empty; string UploadFilePath = ConfigurationManager.AppSettings["FileUploadPath"]; FileHandle objFileHandler = new FileHandle(); HttpPostedFileBase fileUploaded = entity.StudentExcelFile; if (fileUploaded != null) { UploadFilePath = UploadFilePath + FileHandle_Contants.EXCEL_DOCUMENTS; objFileHandler.FileName = fileUploaded.FileName; objFileHandler.MIMEType = fileUploaded.ContentType; objFileHandler.FilePath = UploadFilePath; objFileHandler.Content = fileUploaded.InputStream; if (_iFileHandler.UploadFile(objFileHandler, ref returnFilePath, ref returnErrorMsg)) { entity.StudentExcelFileName = fileUploaded.FileName; entity.StudentExcelFilePath = returnFilePath; } } return entity; }