Ver Mensaje Individual
  #1 (permalink)  
Antiguo 11/10/2010, 08:28
Avatar de Bravenap
Bravenap
 
Fecha de Ingreso: noviembre-2002
Ubicación: Los Arroyos, El Escorial, Madrid
Mensajes: 2.084
Antigüedad: 21 años, 6 meses
Puntos: 4
XML como Net.Mail.Attachment

Buenas tardes.

Estoy tratando de adjuntar un XML sin guardar como archivo a un correo. El XML lo creo en un MemoryStream y creo que ahí está el problema. El XML me aparece siempre cortado, con un máximo de 1,02 KB y 1024 caracteres. Este es el código:
Código vb:
Ver original
  1. 'Generación del XML del pedido
  2.            Dim stream As New IO.MemoryStream
  3.             Try
  4.                 Dim xtw As New XmlTextWriter(stream, Encoding.Default)
  5.                 xtw.WriteStartDocument()
  6.                 xtw.WriteStartElement("Pedido")
  7.                 xtw.WriteElementString("IDPedido", idPedido)
  8.                 xtw.WriteElementString("Nombre", nombre)
  9.                 xtw.WriteElementString("Apellidos", apellidos)
  10.                 xtw.WriteElementString("Correo", correo)
  11.                 xtw.WriteStartElement("Facturacion")
  12.                 xtw.WriteElementString("Nombre", facturaNombre)
  13.                 xtw.WriteElementString("Documento", facturaDocumento)
  14.                 xtw.WriteElementString("Direccion", facturaDireccion)
  15.                 xtw.WriteElementString("Localidad", facturaLocalidad)
  16.                 xtw.WriteElementString("CP", facturaCP)
  17.                 xtw.WriteElementString("Provincia", facturaProvincia)
  18.                 xtw.WriteElementString("TipoIVA", XmlConvert.ToString(carro.TipoIVA))
  19.                 xtw.WriteEndElement() 'Facturacion
  20.                If carro.Envio Then
  21.                     xtw.WriteStartElement("Envio")
  22.                     xtw.WriteElementString("Direccion", envioDireccion)
  23.                     xtw.WriteElementString("Localidad", envioLocalidad)
  24.                     xtw.WriteElementString("CP", envioCP)
  25.                     xtw.WriteElementString("Provincia", envioProvincia)
  26.                     xtw.WriteElementString("Telefono", envioTelefono)
  27.                     xtw.WriteEndElement() 'Envio
  28.                End If
  29.                 xtw.WriteStartElement("Conceptos")
  30.                 For Each dr As DataRow In carro.Conceptos.Rows
  31.                     xtw.WriteStartElement("Concepto")
  32.                     xtw.WriteElementString("IDProducto", dr("IDProducto"))
  33.                     xtw.WriteElementString("Producto", dr("Producto"))
  34.                     xtw.WriteElementString("PrecioUnidad", XmlConvert.ToString(dr("PrecioUnidad")))
  35.                     xtw.WriteElementString("Cantidad", dr("Cantidad"))
  36.                     xtw.WriteElementString("Importe", XmlConvert.ToString(dr("Total")))
  37.                     xtw.WriteEndElement() 'Concepto
  38.                Next
  39.                 xtw.WriteEndElement() 'Conceptos
  40.                xtw.WriteEndElement() 'Pedido
  41.                xtw.WriteEndDocument()
  42.                 stream.Seek(0, IO.SeekOrigin.Begin)
  43.             Catch ex As Exception
  44.                 mens("Error al generar el XML. " & ex.Message, pnlMensajePedido, lblMensajePedido, ex)
  45.                 Exit Sub
  46.             End Try
  47.  
  48.             Dim mAtt As New Attachment(stream, String.Format("{0}.xml", idPedido))
Gracias y un saludo.
__________________
¡¡NO A LA GUERRA!!
Si ponemos a nuestros mensajes títulos adecuados, la gente se animará más a abrirlos y resultarán más útiles en las busquedas. ¡No a los ayuuudaaa, urgenteee y similares!