Mike Phares b99b721458 Moved System.IO references from DMO classes to Static Helpers
Removed nugetSource from pipeline
Removed more comments
Created Static Classes for most DMO / Controller Classes
Push ConfigurationManager.AppSettings to controller
Align Tests with other Projects
2024-12-11 09:29:01 -07:00

47 lines
1.1 KiB
C#

#pragma warning disable CS8019
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
#if !NET8
using System.Web.Mvc;
#endif
using Fab2ApprovalSystem.DMO;
using Fab2ApprovalSystem.Misc;
using System.IO;
using System.Configuration;
#pragma warning restore CS8019
namespace Fab2ApprovalSystem.Utilities;
#if !NET8
public class FileUtilities<T> : Controller // <T> => System.Web.Mvc.FileContentResult
{
public T DownloadFilesFromServer<T>(string pathToFile) {
byte[] fileBytes = GetFile(pathToFile);
var result = File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, pathToFile);
return (T)Convert.ChangeType(result, typeof(T));
}
#else
public class FileUtilities<T> {
#endif
public byte[] GetFile(string s) {
#if !NET8
FileStream fs = System.IO.File.OpenRead(s);
#else
FileStream fs = File.OpenRead(s);
#endif
byte[] data = new byte[fs.Length];
int br = fs.Read(data, 0, data.Length);
if (br != fs.Length)
throw new IOException(s);
return data;
}
}