Noticias Weblogs Foros Wiki Código

RecorteX

» fjmp76
476 usuarios y 237 recortes de código
Usuario

Contraseña
Crear cuenta
Estás viendo los recortes del usuario fjmp76

RSS
Recortes: 35
Registrado: 30/8/2006

Etiquetas:
vbnet (23)
csharp (11)
xml (7)
sql (3)
SQLServer (2)
2005 (1)
js (1)

Traer valores atributos de un xml, cuando usa namespaces

Traer valores atributos de un xml, cuando usa namespaces
 
   Private Function GenerarXML(ByVal xmlStr As String, ByVal appendBuffer As String, ByRef strFileName As String) As String
        Dim xmlStrOriginal As String = xmlStr
        Dim xmlDoc As New XmlDocument
        Dim xnav As XPath.XPathNavigator
        Dim mngr As New XmlNamespaceManager(New NameTable)
        mngr.AddNamespace("ns", "http://www.dominio.com/Schemas/Documentos")
        Dim enc As XmlElement
 
        xmlDoc.LoadXml(xmlStr)
        enc = xmlDoc.SelectSingleNode("Nodo1/Nodo2/ns:nsNodo1/ns:nsNodo2", mngr)
        xmlDoc.LoadXml(enc.OuterXml)
        xnav = xmlDoc.CreateNavigator()
        Att1 = xnav.Evaluate("string(/*/@Att1)")
        Att2 = xnav.Evaluate("string(/*/@Att2)")
 
        Return xmlStr
    End Function
 

Copiar y Pegar objetos al clipboard

Copiar y Pegar objetos en vb.net

Para subir al Clipboard
 
  Dim data As New Object
  Dim data_object As New DataObject
  data_object.SetData("Descripcion o identificador del objeto", data)
  Clipboard.SetDataObject(data_object)
 
Para bajar del Clipboard
 
  Dim iDataObject As IDataObject = Clipboard.GetDataObject()
  If iDataObject.GetDataPresent("Descripcion o identificador del objeto") Then
    Dim data As New Object
    data = DirectCast(iDataObject.GetData("Descripcion o identificador del objeto"), object)
  End If
 

Eliminar acentos en vb.net framework 2.x

 
Imports System
Imports System.Text
Imports System.Text.RegularExpressions.Regex
 
Dim reg As RegularExpressions.Regex
Dim textoOriginal As String = "Mañana será otro día"
'transformación UNICODE
Dim textoNormalizado As String = textoOriginal.Normalize(NormalizationForm.FormD)
 
'coincide todo lo que no sean letras y números ascii o espacio
'y lo reemplazamos por una cadena vacía.
 
reg = New RegularExpressions.Regex("[^a-zA-Z0-9 ]")
Dim textoSinAcentos As String = reg.Replace(textoNormalizado, "")
         
Debug.WriteLine(textoSinAcentos)
'muestra 'Manana sera otro dia'
 

Funcion para eliminar acentos con FrameWork 1.*:

 
Dim ConSignos As String ="áàäéèëíìïóòöúùü�ÀÄÉÈË�?Ì�?ÓÒÖÚÙÜçÇ"
Dim SinSignos As String ="aaaeeeiiiooouuuAAAEEEIIIOOOUUUçÇ"
Dim v as integer
Dim texto as string
 
for(v=0;v<SinSignos.Length;v++) {
 
 Dim i As string=ConSignos.Substring(v,1)
 Dim j As string=SinSignos.Substring(v,1)
 
 texto=texto.replace(i,j)
}
 

Transormacion Xsl en VB.net

Este proceso usa un xml y un xsl de entrada y regresa el xml transformado
 
  -----------------------------------------------------------------------------
    <summary>
    Transforma un xml en otro xml
    </summary>
    <param name="txt">un string que contiene el xml origen</param>
    <param name="xslFile">Archivo xsl para la transformacion</param>
    <returns>el xml transformado</returns>
    -----------------------------------------------------------------------------
   Private Function xslTrans(ByVal txt As String, ByVal xslFile As String) As XmlDocument
       Dim xslTran As New XslTransform
       Dim oDocOut As New XmlDocument
       Dim oDoc As New XmlDocument
       Dim oNav As XPath.XPathNavigator
       Dim oXsl As XmlTextReader
       Try
           oXsl = New XmlTextReader(xslFile)
           oDoc.LoadXml(txt)
           oNav = oDoc.CreateNavigator()
           xslTran.Load(oXsl, Nothing, Me.GetType().Assembly.Evidence)
           oDocOut.Load(xslTran.Transform(oNav, Nothing, New Xml.XmlUrlResolver))
       Catch ex As Exception
           Console.Write("Error:" + vbCr + ex.Message)
       End Try
       oDocOut.Normalize()
       Return oDocOut
   End Function
 

Convertir un texto delimitado por comas a matriz

 
      Function LeeDatos(ByVal txt As String) As Array
        Dim rpr As Integer = 30
        Dim comas As Integer = 0
        Dim reng As Integer = 0
        Dim arr(rpr, 0) As String
        Dim car As Char
        For Each car In txt
            If car <> Chr(10) Then
                If (car = Chr(13)) Then car = ","
                If (car <> ",") Then
                    arr(comas, reng) = arr(comas, reng) + car
                Else
                    If comas = rpr Then
                        comas = 0
                        reng = reng + 1
                        ReDim Preserve arr(rpr, reng)
                    Else
                        comas = comas + 1
                    End If
                End If
            End If
        Next
        ReDim Preserve arr(rpr, reng - 1)
        Return arr
    End Function
 

Determinar los atributos derivados en una tabla de sql server

 
  SELECT b.name AS tabla, a.name AS columna
           FROM syscolumns a INNER JOIN sysobjects b
           ON a.id=b.id
           WHERE b.name='nombretabla'
           AND a.iscomputed=1
 

Extraer el codigo de un Stored Procedure

sp_helptext
This is the same as in SQL server 2000 nothing new here
 
sp_helptext 'dbo.uspGetBillOfMaterials'
 
sys.sql_modules
So this is a new view in SQL Server 2005, what we need is the definition column
 
SELECT definition
FROM sys.sql_modules
WHERE object_id = OBJECT_ID('dbo.uspGetBillOfMaterials')
 
OBJECT_DEFINITION()
This is a new function in SQL Server 2005, just combine it with OBJECT_ID to get the proc code back
 
SELECT OBJECT_DEFINITION (OBJECT_ID('dbo.uspGetBillOfMaterials'))
 
INFORMATION_SCHEMA.ROUTINES
This is the problematic one, if the ROUTINE_DEFINITION is greater than 4000 characters then it will be truncated
 
SELECT ROUTINE_DEFINITION
FROM INFORMATION_SCHEMA.ROUTINES
WHERE SPECIFIC_NAME ='uspGetBillOfMaterials'
AND SPECIFIC_SCHEMA= 'dbo'
 

Crear mensaje

Manda un mensaje de alert de js, desde csharp en una webapp
 
		public static void ShowMessage(System.Web.UI.Page p, string message) 
		{			
			message = message.Replace("'", @"\'");
			message = message.Replace("\"", @"\" + '"');			
			//MessageBox Script
			String scriptString = "<script language=JavaScript>";
			scriptString += "alert('" + message + "');";
			scriptString += "</script>";
			p.RegisterStartupScript("ShowMessage", scriptString);			
		}
 

Obtiene el valor de un atributo que se encuentra en el Request de la pagina.

Obtiene el valor de un atributo que se encuentra en el Request de la pagina.
 
		/// <summary>
		/// Obtiene el valor de un atributo que se encuentra en el Request de la pagina. 
		/// Si no se encuentra el atributo regresa una cadena vacia.
		/// </summary>
		/// <param name="Request">Objeto Request de la pagina.</param>
		/// <param name="attributeName">Nombre del atributo del cual se desea obtener su valor.</param>
		/// <returns>Regresa el valor del atributo, en caso de no existir retorna una cadena vacia.</returns>
		public static string getAttribute(System.Web.HttpRequest Request, string attributeName)
		{
			string attributeValue="";
			try
			{
				attributeValue = Request.QueryString[attributeName];
				if(attributeValue==null || attributeValue.Trim().Equals("")==true)
					attributeValue = "";
			}
			catch{}
			return attributeValue;
		}
 
info@recortex.com - Proyecto: Juanjo Navarro, 2006 - Diseño: Albin - Información legal y técnica