On Tue, 17 Aug 2004 01:49:55 +0200, Guoqi Zheng wrote:
Dear sir,
I am trying to save a binary data by below script, however,it always give me
an error of "Could not find a part of the path "C:\temp\". "
Any idea what I did wrong here?
Public Sub SaveAs(ByVal strPath As String)
If strPath.EndsWith("\") = False Then
strPath += "\"
End If
Dim binaryData() As Byte
binaryData = System.Convert.FromBase64String(m_Filestring)
'Write out the decoded data.
Dim outFile As System.IO.FileStream
Dim OutFileName As String = strPath + m_FileName
outFile = New System.IO.FileStream(OutFileName,
System.IO.FileMode.Create, System.IO.FileAccess.Write)
outFile.Write(binaryData, 0, binaryData.Length - 1)
outFile.Close()
End Sub
Imports System
Imports System.IO
Public Sub SaveAs (ByVal strPath As String)
Dim outFile As FileStream
Try
' you don't need the if test for the path - .net
' already has a class that handles this :)
Dim outFileName As String = Path.Combine (strPath, m_FileName)
Dim binaryData() As Byte = _
Convert.FromBase64String (m_FileString)
outFile = New FileStream _
(outFileName, FileMode.Create, FileAccess.Write)
outFile.Write (binaryData, 0, binaryData.Length)
' insert catch here if you wish to process exceptions,
' other wise, just make sure you do the necessary clean up
' in the finally and the exception will go up to the caller
Finally
If Not outFile Is Nothing Then
outFile.Close()
End If
End Try
End Sub
You may have to show the calling code to get a final answer though...
Since, more then likely the path being passed in is invalid.
--
Tom Shelton [MVP]