public static void AdjuntarArchivo(this MailMessage email, ArchivoAdjunto archivoAdjunto)
        {
            var stream = new MemoryStream(archivoAdjunto.Archivo) { Position = 0 };

            // Create  the file attachment for this e-mail message.
            var data = new Attachment(stream, archivoAdjunto.Nombre, archivoAdjunto.MimeType);
            // Add time stamp information for the file.
            var disposition = data.ContentDisposition;
            disposition.CreationDate = DateTime.Now;
            disposition.DispositionType = archivoAdjunto.MimeType;
            disposition.Size = stream.Length;

            email.Attachments.Add(data);
        }
        public static void SetupNewObject(ArchivoAdjunto nuevoArchivo, IObjectSpace objectSpace, ListView listView)
        {
            var orig = (BasicObject)((PropertyCollectionSource)listView.CollectionSource).MasterObject;

            if (orig == null)
            {
                nuevoArchivo.OriginanteType = null;
                nuevoArchivo.OriginanteKey  = null;
            }
            else if (objectSpace.IsNewObject(orig))
            {
                throw new ArgumentException("No puede vincular con un objeto sin guardar.");
            }
            else
            {
                nuevoArchivo.OriginanteType = ((XPObjectSpace)objectSpace).Session.GetObjectType(orig);
                nuevoArchivo.OriginanteKey  = (int)objectSpace.GetKeyValue(orig);
            }
        }