Align .editorconfig files Move Controller logic to DMO classes GlobalVars.AppSettings = Models.AppSettings.GetFromConfigurationManager(); Question EditorConfig Project level editorconfig Format White Spaces AppSetting when EnvironmentVariable not set Corrective Actions Tests Schedule Actions Tests DMO Tests Controller Tests Get ready to use VSCode IDE
50 lines
1.2 KiB
C#
50 lines
1.2 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) {
|
|
//string templatesPath = GlobalVars.CA_BlankFormsLocation;
|
|
//string fullName = Server.MapPath("~" + filePath);
|
|
|
|
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;
|
|
}
|
|
} |