martes, 16 de mayo de 2017

maxlength en un textbox Multiline

una forma de hacerlo, es asignando el atributo al TextBox desde el código(vb). ejemplo:

CajitaDeTexto..Attributes("maxlength") = 255

jueves, 4 de mayo de 2017

TransactionScope - Timeout

El siguiente código tomará el valor de timeout por defecto (1 min.) para una nueva conexión (el valor de TransactionManager.DefaultTimeout):
 
Using tran As New Transactions.TransactionScope
tran.Complete()
End Using
Sin embargo, este otro código tomará el valor 0, que significa infinito (aunque recuerda que nunca podrá irse más allá del valor de maxTimeout (por defecto 10 min.) establecido en el machine.config).
 
Dim options As New TransactionOptions
Using tran As New TransactionScope(TransactionScopeOption.Required, options)
tran.Complete()
End Using

lunes, 17 de abril de 2017

Recorrer String con texto en XML

En este caso, se requiere agregar la información devuelta por un servicio a una lista de objetos:
xml devuelto por el servicio, almacenado en variable String "salida":
 

        JOSE LUIS                          
        BUGARIN                                 
        PECHE                                   
        19820424
        M
    
Recorremos los nodos del xml:
 
Dim listaResultado = New List(Of ObjetoBE)
Dim obj As New ObjetoBE
Dim xml As XDocument = XDocument.Parse(salida)
Dim resultadoXML = xml.Descendants("RESPUESTA")
If resultadoXML.Count > 0 Then
     For Each nodo As XElement In resultadoXML
        Dim Nnombre = nodo.Descendants("NOMBRES").FirstOrDefault
        obj .Nombres = IIf(IsNothing(Nnombre), "", Nnombre.Value.Trim)

        Dim NApePaterno = nodo.Descendants("APPAT").FirstOrDefault
        obj .ApePaterno = IIf(IsNothing(NApePaterno), "", NApePaterno.Value.Trim)

        Dim NApeMaterno = nodo.Descendants("APMAT").FirstOrDefault
        obj .ApeMaterno = IIf(IsNothing(NApeMaterno), "", NApeMaterno.Value.Trim)

        Dim NFechaNacimiento = nodo.Descendants("FENAC").FirstOrDefault
        obj .FechaNacimiento = IIf(IsNothing(NFechaNacimiento), "", NFechaNacimiento.Value.Trim)

        Dim NSexo = nodo.Descendants("SEXO").FirstOrDefault
        obj .Sexo = IIf(IsNothing(NSexo), "", NSexo.Value.Trim)
    Next

    listaResultado.Add(obj)
Else
    mensaje = "No devolvió resultados"
End If

Convertir una Imagen a Byte y Byte a Imagen

Las siguientes funciones convierten una imagen desde una ruta física a byte y viceversa...
 
Public Function ConvertirImagen_Byte() As Byte()
    Dim rutaImagen = "D:\Documentos\ImagenOrigen\s1.jpg"
    Using foto As FileStream = New FileStream(rutaImagen, FileMode.Open)
        Dim reader As BinaryReader = New BinaryReader(foto)
        Dim imagen(foto.Length) As Byte
        reader.Read(imagen, 0, Convert.ToInt32(foto.Length))
        Return imagen
    End Using
End Function


Protected Sub ConvertirByte_Imagen(ImgBytes As Byte())
    Dim ruta As String = "D:\Documentos\ImagenDestino\s1.jpg" 
    Dim ms As MemoryStream = New MemoryStream(ImgBytes)
    Dim imagen = New System.Drawing.Bitmap(ms)
    imagen.Save(ruta, System.Drawing.Imaging.ImageFormat.Jpeg)
End Sub

jueves, 23 de marzo de 2017

Alert() con salto de línea.

Muchas veces es necesario incluir en un alert varios mensajes de error, la siguiente solución esta planteada para vb.net y C# con Javascript.

VB.NET:
 
Dim strMensaje As String = ""
strMensaje += "- Ingrese texto A." + "\r\n"
strMensaje += "- Ingrese texto B." + "\r\n"
ScriptManager.RegisterStartupScript(Me, Me.GetType, "alerta", "alert('" & strMensaje & "');", True)

C#:
 
String strMensaje = "";
strMensaje += "- Ingrese texto A." + "\\n";
strMensaje += "- Ingrese texto B." + "\\n";
ScriptManager.RegisterStartupScript(this, this.GetType(), "alerta", "alert('" + strMensaje + "');", true);


Saludos.