The name does not exist in the current context and Controller.File(byte[],string) is a method which
Controller code as follows[HttpPost]
public async System.Threading.Tasks.Task<ActionResult> UploadFiles(HttpPostedFileBase[] files)
{
if (ModelState.IsValid)
{
foreach (HttpPostedFileBase fileu in files)
{
if (fileu != null)
{
var InputFileName = Path.GetFileName(fileu.FileName);
var ServerSavePath = Path.Combine(Server.MapPath("~/UploadedFiles/") + InputFileName);
fileu.SaveAs(ServerSavePath);
ViewBag.UploadStatus = files.Count().ToString() + " files uploaded successfully.";
//Api call code as below
var headers = new HttpClient().DefaultRequestHeaders;
string key = "674bc286-9d4f-4dc3-b972-c6b47473905e";
MultipartFormDataContent mForm = new MultipartFormDataContent();
foreach (string file1 in Directory.GetFiles("~/UploadedFiles/"))
mForm.Add(new ByteArrayContent(File.ReadAllBytes(file1)), "File", Path.GetFileName(file1));
HttpClient client = new HttpClient();
foreach (var header in headers)
client.DefaultRequestHeaders.Add("ApiKey", key);
HttpResponseMessage response = client.PostAsync(file1, mForm).Result;
foreach (HttpContent content in response.Content.ReadAsMultipartAsync().Result.Contents)
File.WriteAllBytes(Path.Combine(file1,
content.Headers.ContentDisposition.FileName.Trim('\"')),
content.ReadAsByteArrayAsync().Result);
}
}
}
return View();
}
when i run above code in the below line shows error as follows
The name file1 does not exist in the current context.
the above error shows in below line as follows
HttpResponseMessage response = client.PostAsync(file1, mForm).Result;
Controller.File(byte[],string) is a method which is not valid in the given context
the above error shows in below line as follows
mForm.Add(new ByteArrayContent(File.ReadAllBytes(file1)), "File", Path.GetFileName(file1));
mForm.Add(new ByteArrayContent(File.ReadAllBytes(file1)), "File", Path.GetFileName(file1));