|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
DimeAttachment save to diskI'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 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. 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 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.
Broken References
check point inside "cirkle" (basketball) Exposing properties of a class within a class Unresponsive UI during lengthy operation ? Windows Services works for years/months/weeks, then chokes New bee:How do i make an .exe file in VS 2005? Count lines in multi-line textbox Can't Figure Out Correct Syntax Using a Structure in a Class Problems with Excel Object Library |
|||||||||||||||||||||||