I want to create a web service to upload txt files and store them, this is my service:
[WebMethod]
public bool SaveFiles(HttpPostedFileBase[] files)
{
try
{
foreach (HttpPostedFileBase file in files)
{
var InputFileName = Path.GetFileName(file.FileName);
var ServerPath = Path.Combine(string.Format("{0}{1}"), "UploadedFiles", InputFileName);
file.SaveAs(ServerPath);
}
return true;
}
catch (Exception ex)
{
}
return true;
}
and on the client side, who is consuming the service I have in my controller
[HttpPost]
public ActionResult Upload(HttpPostedFileBase[] files)
{
ViewBag.status = "";
if (ModelState.IsValid)
{
ReferenciaMiServicio.MiServicioSoapClient service = new ReferenciaMiServicio.MiServicioSoapClient();
var response = service.SaveFiles(files);
// Falta mandar a¡error cuando la carga no fue valida
ViewBag.status = "Archivos cargados satisfactoriamente";
}
return View();
}
But I get this error in the controller:
ErrorCS1503 Argumento 1: Cannot convert from 'System.Web.HttpPostedFileBase[]' a 'PruebaMiServicio.ReferenciaMiServicio.HttpPostedFileBase[]'
and exactly highlights the error in files
var response = service.SaveFiles(files);
You could help me with the solution, this is all C# asp.net
Thank you!