Home All Groups Group Topic Archive Search About

DimeAttachment save to disk

Author
15 Feb 2006 5:31 PM
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

Author
15 Feb 2006 6:45 PM
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.
Author
20 Feb 2006 8:24 PM
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. 

- Lee
Author
22 Feb 2006 2:37 PM
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.