I hope someone can advise me on the situation I have. I have two asp mvc applications, one is the desktop and the other the mobile version. I want to be able to write files uploaded on the mobile version to a folder in the desktop version, because this latter holds the administrative section of the application. I can download files from one to the other with the WebClient class of .Net, but I haven't been able to upload files from one to the other. I have a console application to test the uploading and whenever I try it I get an error saying "access is denied" to the folder in the application. I tried creating a folder in the application outside of the App_Data folder because I thought this folder is restricted, but I get the same error. Can someone please advise me what to do? I've read googling here and there that this can be easily solved from the IIS administration, but I doubt the guys in my hosting company will be willing to grant me any rights on the administration of any application. The code I wrote only fails when I try to save the files. Here is the code of the site that receives the request:
[HttpPost]
[AllowAnonymous]
public string SubirArchivosRegistro(HttpPostedFileBase file)
{
string MensajeError = "";
string path = "";
string Success = " El (los) diplomas subidos exitosamente ";
try
{
if (file != null && file.ContentLength > 0)
{
path = Path.Combine(Server.MapPath("~/ArchivosRegistroUsuarios"), file.FileName);
file.SaveAs(path);
Success += file.FileName +",";
}
///return path;
return Success;
}
catch(Exception ex)
{
MensajeError = "Ha ocurrido un error, no se pudieron subir los archivos solicitados "+ex.Message;
return MensajeError;
}
}
And this is the code in the client part (none of the codes is failing, it's just a permissions issue):
try
{
WebClient cliente = new WebClient();
if (GendarmeriaCertNombre != null && GendarmeriaCertNombre.ElementAt(0) != null)
{
gendarmeria = new List<Guid?>();
gendarmeriaNombre = new List<string>();
foreach (HttpPostedFileBase file in GendarmeriaCertNombre)
{
if (file != null)
{
string filename = Path.GetFileName(file.FileName);
Guid guidnum = _fileStore.SaveUploadedFile(file, "gendarmeria");
gendarmeria.Add(guidnum);
gendarmeriaNombre.Add(file.FileName);
string ruta = _fileStore.GetDiskLocation(guidnum);
byte[] respuesta = cliente.UploadFile("http://localhost/DiplomadoEnMandoPolicial/Account/SubirArchivosRegistro", "POST", ruta);
response = System.Text.Encoding.ASCII.GetString(respuesta);
}
}
if (gendarmeria != null && gendarmeria.Count > 0 && gendarmeriaNombre != null && gendarmeriaNombre.Count > 0)
{
registro.GendarmeriaCertificado = String.Join(",", gendarmeria.Select(t => t.Value.ToString("D")));
registro.GendarmeriaCertNombre = String.Join(",", gendarmeriaNombre);
}
}
if (CursoInacipeCertNombre != null && CursoInacipeCertNombre.ElementAt(0) != null)
{
inacipe = new List<Guid?>();
inacipeNombre = new List<string>();
foreach (HttpPostedFileBase file in CursoInacipeCertNombre)
{
if (file != null)
{
string filename = Path.GetFileName(file.FileName);
Guid guidnum = _fileStore.SaveUploadedFile(file, "inacipe");
inacipe.Add(guidnum);
inacipeNombre.Add(file.FileName);
string ruta = _fileStore.GetDiskLocation(guidnum);
byte[] respuesta = cliente.UploadFile("http://localhost/DiplomadoEnMandoPolicial/Account/SubirArchivosRegistro", "POST", ruta);
response = System.Text.Encoding.ASCII.GetString(respuesta);
}
}
if (inacipe != null && inacipe.Count > 0 && inacipeNombre != null && inacipeNombre.Count > 0)
{
registro.CursoInacipeCertificado = String.Join(",", inacipe.Select(t => t.Value.ToString("D")));
registro.CursoInacipeCertNombre = String.Join(",", inacipeNombre);
}
}
if (CursoCideCertNombre != null && CursoCideCertNombre.ElementAt(0) != null)
{
cide = new List<Guid?>();
cideNombre = new List<string>();
foreach (HttpPostedFileBase file in CursoCideCertNombre)
{
if (file != null)
{
string filename = Path.GetFileName(file.FileName);
Guid guidnum = _fileStore.SaveUploadedFile(file, "cide");
cide.Add(guidnum);
cideNombre.Add(file.FileName);
string ruta = _fileStore.GetDiskLocation(guidnum);
byte[] respuesta = cliente.UploadFile("http://localhost/DiplomadoEnMandoPolicial/Account/SubirArchivosRegistro", "POST", ruta);
response = System.Text.Encoding.ASCII.GetString(respuesta);
}
}
if (cide != null && cide.Count > 0 && cideNombre != null && cideNombre.Count > 0)
{
registro.CursoCideCertificado = String.Join(",", cide.Select(t => t.Value.ToString("D")));
registro.CursoCideCertNombre = String.Join(",", cideNombre);
}
cliente.Dispose();
}
}
Well, that's the problem, I'm open to any suggestions.