Hello,
I'm using this code to copy binary files to my IIS Server:
Dim imgStream As Stream = ImageFile.PostedFile.InputStream
Dim imgData(ImageFile.PostedFile.ContentLength) As Byte
Dim intFileNameLength As Integer
Dim strFileName As String
Dim Filename As File
Dim strFileNamePath As String
' read uploaded file in the buffer using InputStream object
imgStream.Read(imgData, 0, ImageFile.PostedFile.ContentLength)
'full path to uploaded file on client’s system
strFileNamePath = ImageFile.PostedFile.FileName
intFileNameLength = InStr(1, StrReverse(strFileNamePath), "\"
strFileName = Mid(strFileNamePath, (Len(strFileNamePath) - intFileNameLength) + 2)
WriteToServer(ConfigurationSettings.AppSettings("TempServerPath" + strFileName, imgData)
Public Sub WriteToServer(ByVal strPath As String, ByRef Buffer As Byte())
'copy the selected file to the Server
Dim myFileStream As FileStream
Dim NewFile As BinaryWriter
myFileStream = File.Create(Path:=strPath)
Try
'Create a file
NewFile = New BinaryWriter(output:=myFileStream)
'Write data to the file
NewFile.Write(Buffer, 0, Buffer.Length)
Catch exc As Exception
lblMsg.Text = "<SCRIPT language = 'javascript'>alert('Error: " & "\n\n" & exc.Message & "');</SCRIPT>"
Finally
'Close file
myFileStream.Close()
End Try
End Sub
It's working fine for binary files (*.jpg,*.gif,*.png...) but for text ones (*.htm, *.txt...), it's copying an empty file to my TempServerPath directory.
Anybody has an idea why ?
I'm using this code to copy binary files to my IIS Server:
Dim imgStream As Stream = ImageFile.PostedFile.InputStream
Dim imgData(ImageFile.PostedFile.ContentLength) As Byte
Dim intFileNameLength As Integer
Dim strFileName As String
Dim Filename As File
Dim strFileNamePath As String
' read uploaded file in the buffer using InputStream object
imgStream.Read(imgData, 0, ImageFile.PostedFile.ContentLength)
'full path to uploaded file on client’s system
strFileNamePath = ImageFile.PostedFile.FileName
intFileNameLength = InStr(1, StrReverse(strFileNamePath), "\"
strFileName = Mid(strFileNamePath, (Len(strFileNamePath) - intFileNameLength) + 2)
WriteToServer(ConfigurationSettings.AppSettings("TempServerPath" + strFileName, imgData)
Public Sub WriteToServer(ByVal strPath As String, ByRef Buffer As Byte())
'copy the selected file to the Server
Dim myFileStream As FileStream
Dim NewFile As BinaryWriter
myFileStream = File.Create(Path:=strPath)
Try
'Create a file
NewFile = New BinaryWriter(output:=myFileStream)
'Write data to the file
NewFile.Write(Buffer, 0, Buffer.Length)
Catch exc As Exception
lblMsg.Text = "<SCRIPT language = 'javascript'>alert('Error: " & "\n\n" & exc.Message & "');</SCRIPT>"
Finally
'Close file
myFileStream.Close()
End Try
End Sub
It's working fine for binary files (*.jpg,*.gif,*.png...) but for text ones (*.htm, *.txt...), it's copying an empty file to my TempServerPath directory.
Anybody has an idea why ?