public IActionResult OnPost() { var FileToUpload = Path.Combine(_env.WebRootPath, "Files", PlayerFile.FileName); //this variable consists of file path Console.WriteLine("File Name : " + FileToUpload); using (var FStream = new FileStream(FileToUpload, FileMode.Create)) { PlayerFile.CopyTo(FStream); //copy the file into FStream variable } DatabaseConnect DbCon = new DatabaseConnect(); SqlConnection conn = new SqlConnection(DbCon.DatabaseString()); conn.Open(); using (SqlCommand command = new SqlCommand()) { command.Connection = conn; command.CommandText = @"INSERT FileTable (PlayerName, FileName) VALUES (@PlayerName, @FName)"; command.Parameters.AddWithValue("@PlayerName", PlayerFileRec.PlayerName); command.Parameters.AddWithValue("@FName", PlayerFile.FileName); Console.WriteLine("File name : " + PlayerFileRec.PlayerName); Console.WriteLine("File name : " + PlayerFile.FileName); command.ExecuteNonQuery(); } return(RedirectToPage("/index")); }