I want to upload image to the image folder, but it will show this error. fronted is Angular 7.
Asp.Net Core MVC
CustomerRepo.cs
public bool AddCustomer(ExpressWebApi.Models.CustomerModel customer)
{
SqlConnection con =new SqlConnection();
con.ConnectionString="Data Source=.;Initial Catalog=BLAbLADB;Persist Security Info=True;User ID=sa;Password=sasasa";
SqlCommand cmd = new SqlCommand();
cmd.Connection=con;
//file upload start-----------------------
string imageName = null;
var httpRequest = HttpContext.Current.Request;
//upload the image
var postedFile = httpRequest.Files["cusImage"];
//Current custome filename
imageName = new string(Path.GetFileNameWithoutExtension(postedFile.FileName).Take(10).ToArray()).Replace(" ", "-");
imageName = imageName + DateTime.Now.ToString("yymmssfff") + Path.GetExtension(postedFile.FileName);
var filePath = HttpContext.Current.Server.MapPath("~/Images/" + imageName);
postedFile.SaveAs(filePath);
//file upload end-------------------------
cmd.CommandText=$@"INSERT INTO Customer ([CusName], [CusPassword], [CusEmail], [CusDob], [CusImage]) VALUES ('{customer.CusName}', '{customer.CusPassword}', '{customer.CusEmail}', '{customer.CusDob}','{imageName}');";
cmd.Connection.Open();
cmd.ExecuteNonQuery();
cmd.Connection.Close();
return true;
}
register.html - in Angular Application
var customerData = {
"cusName": form.value.userName,
"cusPassword": form.value.password,
"cusEmail": form.value.email,
"cusDob": form.value.dob,
"cusImage" : this.fileToUpload
};
//for photo upload start---------------------------------
handleFileInput(file:FileList){
this.fileToUpload=file.item(0);
//show image preview
var reader = new FileReader();
reader.onload=(event:any)=>{
this.imageUrl=event.target.result;
}
reader.readAsDataURL(this.fileToUpload);
}
//for photo upload end---------------------------------
Error CS0117 'HttpContext' does not contain a definition for 'Current'