doc.Attachments.Add "c:\archivo.txt"
O pasandole un ADODB.Stream cargado y el nombre:
Set oStream = CreateObject("ADODB.Stream")
oStream.Open
oStream.Type = 1 ' adTypeBinary
oStream.LoadFromFile "c:\archivo.txt"
doc.Attachments.Add oStream, "archivo.txt" ' Si paso un stream debo especificar el nombre
dapihttp implementa la coleccion Attachments del objeto Document, pero en solo-lectura, es decir, no puedo agregar nuevos adjuntos.
Para poder agregar un nuevo adjunto vamos a utilizar el metodo CustomScript del listener (ver Ejemplo de llamada a metodo no implementado en dapihttp). Vamos a utlizar el metodo del stream, ya que del lado del servidor no tengo acceso a mis archivos locales.
Creamos un Sub:
Sub DocAttachmentsAdd(ByRef pDoc, ByRef pStream, ByVal pName)
Set oDom = pDoc.Session.XML.NewDom
oDom.loadXML ""
oDom.documentElement.setAttribute "method", "CustomScript"
' Cargamos un esquema que nos va a permitir manejar binarios
oDom.documentElement.setAttribute "xmlns:dt", "urn:schemas-microsoft-com:datatypes"
'Arg 0: El script
' node y newObj tambien estan disponibles como variables
Set node = oDom.createNode("element", "item", "")
node.Text = "Set obj = Session(CStr(Arg(1)))" & vbCrLf & _
"Set node = oReq.documentElement.childNodes(2)" & vbCrLf & _
"Set newObj = Server.CreateObject(""ADODB.Stream"")" & vbCrLf & _
"newObj.Type = 1 ' adTypeBinary" & vbCrLf & _
"newObj.Open" & vbCrLf & _
"If Not IsNull(node.nodeTypedValue) Then newObj.Write node.nodeTypedValue" & vbCrLf & _
"obj.Attachments.Add newObj, CStr(Arg(3))"
oDom.documentElement.AppendChild node
'1: Guid
Set node = oDom.createNode("element", "item", "")
node.Text = pDoc.ObjGuid
oDom.documentElement.AppendChild node
'2: File
Set node = oDom.createNode("element", "item", "")
' Utilizamos bin encoded en Base64
node.dataType = "bin.base64"
node.nodeTypedValue = pStream.Read
oDom.documentElement.AppendChild node
'3: Att name
Set node = oDom.createNode("element", "item", "")
node.Text = pName
oDom.documentElement.AppendChild node
pDoc.Session.HttpCallDom (oDom)
End Sub
Para llamarlo:
Set oStream = CreateObject("ADODB.Stream")
oStream.Open
oStream.Type = 1 ' adTypeBinary
oStream.LoadFromFile "c:\archivo.txt"
DocAttachmentsAdd doc, oStream, "archivo.txt"
voila
No hay comentarios:
Publicar un comentario