I'm getting files from Angular with this code:
var httpPostedFile = HttpContext.Current.Request.Files["file"];
This is my directory:
string folderExists = (HttpContext.Current.Server.MapPath("~/abc"));
How can I save my files into that folder?
for (int i = 0; i < HttpContext.Current.Request.Files.Count; i++)
{
var FileName = httpPostedFile.FileName;
int fileSize = httpPostedFile.ContentLength;
byte[] fileByteArray = new byte[fileSize];
httpPostedFile.InputStream.Read(fileByteArray, 0, fileSize);
string fileLocation = Path.Combine(HttpContext.Current.Server.MapPath("~/App_Data/uploads"), FileName);
if (!Directory.Exists(HttpContext.Current.Server.MapPath("~/App_Data/uploads")))
Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/App_Data/uploads"));
httpPostedFile.SaveAs(fileLocation);
}
I'm saving the files into the folder, but I want to store those files in SQL database.
My file structure:
public class FileTable
{
[Key]
public int Id { get; set; }
public byte[] FileData { get; set; }
public string FileName { get; set; }
}
How can I store my file in the database?