In this code I am using the asmx service using ajax, my files are stored in localhost, but when I upload it to a server on the internet it does not save, I gave it full control permissions in IIS. and I still do not find the problem.
- var form_data = new FormData();
-
- form_data.append("Archivo", $('#txtArchivo')[0].files[0])
- form_data.append("Fecha", $("#txtTitulo").val())
- form_data.append("Descripcion", $("#txtActuaciones").val())
- form_data.append("Id", $("#txtRadicadoOculto").val())
- form_data.append("Carpeta", $("#inputSuccess").val())
- console.log("datos" + JSON.stringify(form_data))
- var param = {
- Id: $("#txtRadicadoOculto").val(),
- Fecha: $("#txtTitulo").val(),
- Descripcion: $("#txtActuaciones").val(),
- Archivo: form_data
- };
- console.log("con el archivo" + JSON.stringify(param));
-
-
- $.ajax({
- url: '<%=ResolveUrl("ArchivoActuacion.asmx/Guardar")%>',
- type: 'POST',
- data: form_data,
-
- processData: false,
- contentType: false,
- beforeSend: function () {
- $("#load").fadeIn(100);
- $('#loading').css({
- 'display': 'block'
- });
- },
- success: function (data) {
- console.log("mi respuesta" + data.success)
- $("#load").fadeOut(200);
- if (data.success != true) {
- alert("No pudo guardarse! " + data.success)
- } else {
- alert("Guardado Satisfactoriamente!")
- $("#txtTitulo").val("")
- $("#txtActuaciones").val("")
- $('#txtArchivo').val("");
- }
-
-
- },
- error: function (XMLHttpRequest, textStatus, errorThrown) {
- var err = eval("(" + XMLHttpRequest.responseText + ")");
- alert("ojo" + err.Message)
- console.log("Ajax Error!");
- $("#load").fadeOut(200);
- }
- });
- public class ArchivoActuacion : System.Web.Services.WebService {
- public ArchivoActuacion()
- {
-
-
-
- }
-
- [WebMethod]
- [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
- public void Guardar()
- {
- HttpContext Contexto = HttpContext.Current;
-
- string radicado = Contexto.Request.Form["Id"];
-
- string fecha = Contexto.Request.Form["Fecha"];
- string descripcion = Contexto.Request.Form["Descripcion"];
- string carpeta = Contexto.Request.Form["Carpeta"];
- HttpFileCollection ColeccionArchivos = Context.Request.Files;
-
-
- string NombreArchivo = "";
- string directorio = "";
- int ArchivoActual = 0;
-
- SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConLegasis"].ConnectionString);
-
-
- if (ColeccionArchivos.Count != 0)
- {
-
- Contexto.Server.ScriptTimeout = 2400;
- NombreArchivo = ColeccionArchivos[0].FileName;
- String DatosArchivo = System.IO.Path.GetFileName(ColeccionArchivos[0].FileName);
- string filename = string.Format("{0}{1:yyyyMMdd_HHmmss}.{2}", Path.GetFileNameWithoutExtension(ColeccionArchivos[ArchivoActual].FileName), DateTime.Now, Path.GetExtension(ColeccionArchivos[ArchivoActual].FileName));
- string cadena = filename.Replace(" ", String.Empty);
-
- if (Directory.Exists(Server.MapPath(carpeta)))
- {
-
- String CarpetaParaGuardar = Server.MapPath(carpeta + "\\") + Path.GetFileName(cadena);
- ColeccionArchivos[0].SaveAs(CarpetaParaGuardar);
- directorio = "./" + carpeta + "/" + Path.GetFileName(cadena);
- var strSQL = "INSERT INTO Actuacion_simple VALUES(" + radicado + ",'" + fecha + "', '" + descripcion.ToUpper().ToString() + "','" + directorio + "')";
- var cmd = new SqlCommand(strSQL, cn);
- cn.Open();
- cmd.ExecuteNonQuery();
- cn.Close();
- Contexto.Response.ContentType = "application/json";
- Contexto.Response.Write("{\"success\":true,\"msg\":\"" + NombreArchivo + "\"}");
- Contexto.Response.End();
-
- }
- else
- {
- Directory.CreateDirectory(Server.MapPath(carpeta));
- String CarpetaParaGuardar = Server.MapPath(carpeta + "\\") + Path.GetFileName(cadena);
- ColeccionArchivos[0].SaveAs(CarpetaParaGuardar);
- directorio = "./" + carpeta + "/" + Path.GetFileName(cadena);
- var strSQL = "INSERT INTO Actuacion_simple VALUES(" + radicado + ",'" + fecha + "', '" + descripcion.ToUpper().ToString() + "','" + directorio + "')";
- var cmd = new SqlCommand(strSQL, cn);
- cn.Open();
- cmd.ExecuteNonQuery();
- cn.Close();
- Contexto.Response.ContentType = "application/json";
- Contexto.Response.Write("{\"success\":true,\"msg\":\"" + NombreArchivo + "\"}");
- Contexto.Response.End();
- }
- }
- else
- {
- directorio = "";
- var strSQL = "INSERT INTO Actuacion_simple VALUES(" + radicado + ",'" + fecha + "', '" + descripcion.ToUpper().ToString() + "','" + directorio + "')";
- var cmd = new SqlCommand(strSQL, cn);
- cn.Open();
- cmd.ExecuteNonQuery();
- cn.Close();
- Contexto.Response.ContentType = "application/json";
- Contexto.Response.Write("{\"success\":true,\"msg\":\"" + NombreArchivo + "\"}");
- Contexto.Response.End();
- }
-
-
-
-
- }
- }
