En el servidor de base de datos, en la carpeta Security / Logins, agregar el usuario:
En User Mapping, marcar la base de datos a la que se quiera acceder, y marcar db_datareader:
Agregar el usuario:
En Membership, darle el rol db_datareader
Input type file - subir archivos MVC
*** es importante poner el multipart/form-data !!!!! ***
*** el method tiene que ser Post ***
Vista
*** el method tiene que ser Post ***
Vista
@using (Html.BeginForm("GuardarPlanilla", "Avales", FormMethod.Post, new { id = "FormGestionPlanilla", enctype = "multipart/form-data" }))
{
@Html.TextBoxFor(m => m.RutaPlanilla, new { type = "file", Class = "btn btn-success navbar-btn" })
}
Controller
[HttpPost]
public ActionResult GuardarPlanilla(AvalPlanillaVM modelo, AvalPlanillaDetalleVM modeloDet)
{
var archivo = this.HttpContext.Request.Files.Get("RutaPlanilla");
var file = (System.Web.HttpPostedFileWrapper)(archivo);
var nombreArchivo = file.FileName.Substring(file.FileName.LastIndexOf("\\") + 1);
var rutaArchivo = this.Server.MapPath("../XLS/" + nombreArchivo);
file.SaveAs(rutaArchivo);
}
Leer excel con OpenXml y retornarlo en una lista genérica
Uso:
//en el caso de que sea una fecha, hay que parsearla
Código de ExcelLogica: http://desaX.blogspot.com.uy/2017/12/clase-excellogica.html
var excel = ExcelLogica.Leer("c:\\temp\\excel1.xlsx");
foreach (var fila in excel)
{
var f = (string[])fila;
//en el caso de que sea una fecha, hay que parsearla
fecha = DateTime.FromOADate(int.Parse(f[2]));
Console.WriteLine(f[0] + " " + f[1] + " " + fecha);
}
Código de ExcelLogica: http://desaX.blogspot.com.uy/2017/12/clase-excellogica.html
Invalidar ModelState manualmente
El primer campo es el key, es el nombre del atributo para el cual se desplegara el mensaje
ModelState.AddModelError("Usuario", "mensaje");
ModelState.AddModelError("Usuario", "mensaje");
Acceder a otros campos dentro de un CustomAttribute
Ej, para acceder al valor del atributo FechaHasta:
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
var otherValue = validationContext.ObjectType.GetProperty("FechaHasta").GetValue(validationContext.ObjectInstance, null);
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
var otherValue = validationContext.ObjectType.GetProperty("FechaHasta").GetValue(validationContext.ObjectInstance, null);
Refused to display 'site' in a frame because it set 'X-Frame-Options' to 'sameorigin'
En global.asax, agregar:
AntiForgeryConfig.SuppressXFrameOptionsHeader = true;
En web.config:
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="X-Frame-Options" value="AllowAll" />
</customHeaders>
</httpProtocol>
</system.webServer>
Validaciones con DataAnnotations
1. Definir los DataAnnotations en el ViewModel para cada atributo que se quiera validar:
[Required(ErrorMessage = "Ingrese el nombre")]
public string Nombre { get; set; }
*** El objeto ModelState contiene toda la información de los errores ocurridos, en ModelState.Values
[Required(ErrorMessage = "Ingrese el nombre")]
public string Nombre { get; set; }
2. Agregar la verificación en el Action:
public ActionResult Guardar(PersonaViewModel persona)
{
if (ModelState.IsValid)
{
...
return View();
} else
{
ViewBag.Mensaje = "Error en los datos ingresados, debe completar los campos requeridos";
return View("Error");
}
}
*** El objeto ModelState contiene toda la información de los errores ocurridos, en ModelState.Values
*** Solo con esto, ya queda funcionando la validación del lado del servidor.
*** Para que la validación se haga también del lado del cliente, se debe agregar lo siguiente:
*** Para que la validación se haga también del lado del cliente, se debe agregar lo siguiente:
1. Agregar los siguientes scripts:
<script src="/Scripts/jquery.validate.js"></script>
<script src="/Scripts/jquery.validate.unobtrusive.js"></script>
<script src="/Scripts/jquery.validate.js"></script>
<script src="/Scripts/jquery.validate.unobtrusive.js"></script>
2. Agregar los ValidationMessages para cada atributo:
<div class="field-validation-error">@Html.ValidationMessageFor(m => m[i].Path)</div>
@Html.TextBoxFor(m => m[i].Path)
3. También se puede agregar el ValidationSummary, que sirve para mostrar un resumen de todos los campos con error. Esto en general se agrega al final de la página:
<div class="validation-summary-errors">
@Html.ValidationSummary()
</div>
*** Tener en cuenta que el comportamiento de las validaciones en IE a veces es diferente a Chrome ***
Generar excel con OpenXML y retornarlo en el Response
public ActionResult DesplegarExcel(SubdiarioViewModel subdiario)
{
//lista es una estructura generica (ej, un DTO), con cualquier complejidad
var ret = ExcelLogica.GenerarOpenXml(lista, "A1:AB1");
Response.Clear();
Response.ContentType = "application/force-download";
Response.AddHeader("content-disposition", "attachment; filename=" + nombre);
Response.BinaryWrite(ret);
Response.Flush();
Response.End();
return new EmptyResult();
//lista es una estructura generica (ej, un DTO), con cualquier complejidad
var ret = ExcelLogica.GenerarOpenXml(lista, "A1:AB1");
Response.Clear();
Response.ContentType = "application/force-download";
Response.AddHeader("content-disposition", "attachment; filename=" + nombre);
Response.BinaryWrite(ret);
Response.Flush();
Response.End();
return new EmptyResult();
Configurar Handbrake para enviar videos por whatsapp
Elegir Android 480p30
Y en quality, bajarlo hasta que diga 26
Y en quality, bajarlo hasta que diga 26
Unable to start debugging on the web server. Connection Refused
No se porque ocurre.
Se puede solucionar creando un website en otro puerto, e indicarle en la ficha Web, dicha url
ej:
localhost:8083/SitioWeb
Se puede solucionar creando un website en otro puerto, e indicarle en la ficha Web, dicha url
ej:
localhost:8083/SitioWeb
Fileupload con bootstrap - soporta multiples archivos
1. Instalar
bootstrap
fileinput (de http://plugins.krajee.com/file-input)
jQuery
2. Agregar las referencias
<link href="/FileUp2/Content/themes/base/jquery-ui.css" rel="stylesheet"/>
<link href="/FileUp2/Content/bootstrap.css" rel="stylesheet"/>
<link href="/FileUp2/Content/bootstrap-theme.css" rel="stylesheet"/>
<script src="/FileUp2/Scripts/jquery-1.12.4.js"></script>
<script src="/FileUp2/Scripts/bootstrap.js"></script>
<script src="/FileUp2/Scripts/bootstrap-fileinput/js/fileinput.js"></script>
bootstrap
fileinput (de http://plugins.krajee.com/file-input)
jQuery
2. Agregar las referencias
<link href="/FileUp2/Content/themes/base/jquery-ui.css" rel="stylesheet"/>
<link href="/FileUp2/Content/bootstrap.css" rel="stylesheet"/>
<link href="/FileUp2/Content/bootstrap-theme.css" rel="stylesheet"/>
<script src="/FileUp2/Scripts/jquery-1.12.4.js"></script>
<script src="/FileUp2/Scripts/bootstrap.js"></script>
<script src="/FileUp2/Scripts/bootstrap-fileinput/js/fileinput.js"></script>
3. Agregar el codigo a la vista:
<div class="file-loading">
<input id="input-44" name="input44[]" type="file" multiple>
</div>
<script>
$(document).on('ready', function() {
$("#input-44").fileinput({
uploadUrl: '/FileUp2/Archivos/Subir',
maxFilePreviewSize: 10240
});
});
</script>
4. En el controller llamado Archivos, agregar el método Subir:
[HttpPost]
public ContentResult Subir()
{
HttpPostedFileBase hpf = null;
foreach (string file in Request.Files)
{
hpf = Request.Files[file] as HttpPostedFileBase;
if (hpf.ContentLength == 0)
continue;
string savedFileName = Path.Combine(Server.MapPath("~/App_Data"), Path.GetFileName(hpf.FileName));
hpf.SaveAs(savedFileName); // Save the file
}
// Returns json
return Content("{\"name\":\"" + hpf.FileName + "\",\"type\":\"" + hpf.ContentType + "\",\"size\":\"" + string.Format("{0} bytes", hpf.ContentLength) + "\"}", "application/json");
}
Grabar multitrack con Ableton Live
1. Agregar los instrumentos que se van a utilizar.
2. Armar el instrumento que se quiere grabar (si se quiere grabar de mas de una fuente en simultaneo, hacer click con la tecla ctrl presionada)
3. Cambiar a vista de Arrangement
4. Presionar el boton grabar, y luego el boton play para comenzar.
2. Armar el instrumento que se quiere grabar (si se quiere grabar de mas de una fuente en simultaneo, hacer click con la tecla ctrl presionada)
3. Cambiar a vista de Arrangement
4. Presionar el boton grabar, y luego el boton play para comenzar.
Suscribirse a:
Entradas (Atom)





