DimeAttachment save to disk

L

Lee Blue

I've been having difficulty in finding a good example of how to save a
DimeAttachment out to disk in VB.Net. I've got past getting the attachment
into my <WebMethod> from a VB6 Soap Client using the low level API. Now it's
on the server in a Web Service written in VB.NET you'd think it would be
easy to save it out to disk. The DimeAttachment exposes a stream. What I
think I should do is use a Byte array to buffer a write to the file system.
Has anyone done this?

- Lee
 
A

alantolan

You can just read from the Dime stream and write to an open file stream
on disk

e.g.

Public Shared Sub WriteFileStream( _
ByVal fullName As String, _
ByVal instream As Stream _
)

Dim fs As New FileStream(fullName, FileMode.CreateNew)
Dim dataInt As Integer

While True
dataInt = instream.ReadByte()
If (dataInt = -1) Then
Exit While
End If
fs.WriteByte(CType(dataInt, Byte))
End While
fs.Close()

end sub


'fullName' is where you wish to put the file
'instream' is the Dime stream


The casting looks a tad strange I admit but blame the streams

ReadByte() returns an integer
WriteByte() writes a byte.


Also, if you do not have code for getting at the Dime stream, you can
use

Dim soapCon As SoapContext = RequestSoapContext.Current
WriteFileStream(fileName, soapCon.Attachments(0).Stream)


hth,
Alan.
 
L

Lee Blue

Alan,

Thanks. That worked great. Is there any concerns I should have for using
this technique to upload large files (30mb). Is the stream being buffered
during the upload.

- Le
 
A

AlanT

I'm afraid that I don't know the answer to that one. We have been using
the above code with files of 2MB +- and it works fine. We don't need
to worry about larger files so it was not tested with anything larger
than about 5 MB.

Alan.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top