I've got the upload part done, but the problem I have is that the image must be in a bitmap form. What happens is that when the user has the image they want to use it's converted into a Bitmap. When I run it on my PC it's fine but when I run it off the server it gives me an error that the file is missing. The original image resides on the clients PC not on the server Is there a way to get around this?
Public Sub ConvertImage(ByVal Filename As String, _
ByVal DesiredFormat As System.Drawing.Imaging.ImageFormat, _
ByVal NewFilename As String)
' Takes a filename and saves the file in a new format
Try
Dim imgFile As Image = _
System.Drawing.Image.FromFile(Filename)
imgFile.Save(NewFilename, DesiredFormat)
Catch ex As Exception
Throw ex
End Try
End Sub
Private Sub btnUpload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpload.Click
Dim strFileName As String
Dim strFilePath As String
Dim strFolder As String
strFolder = "c:\inetpub\
strFileName = Image1.ImageUrl()
'Create the directory if it does not exist.
If (Not Directory.Exists(strFolder)) Then Directory.CreateDirectory(strFolder)
strFilePath = strFolder & txtSaveAs.Text & ".bmp"
If File.Exists(strFilePath) Then
lblUploadResult.Text = strFilePath & " already exists on the server!"
Else
'Converts the uploaded to bitmap and saves it to the server
ConvertImage(strFileName, System.Drawing.Imaging.ImageFormat.Bmp, strFilePath)
lblUploadResult.Text = txtSaveAs.Text & ".bmp" & " has been successfully uploaded."
End If
End Sub
Public Sub ConvertImage(ByVal Filename As String, _
ByVal DesiredFormat As System.Drawing.Imaging.ImageFormat, _
ByVal NewFilename As String)
' Takes a filename and saves the file in a new format
Try
Dim imgFile As Image = _
System.Drawing.Image.FromFile(Filename)
imgFile.Save(NewFilename, DesiredFormat)
Catch ex As Exception
Throw ex
End Try
End Sub
Private Sub btnUpload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpload.Click
Dim strFileName As String
Dim strFilePath As String
Dim strFolder As String
strFolder = "c:\inetpub\
strFileName = Image1.ImageUrl()
'Create the directory if it does not exist.
If (Not Directory.Exists(strFolder)) Then Directory.CreateDirectory(strFolder)
strFilePath = strFolder & txtSaveAs.Text & ".bmp"
If File.Exists(strFilePath) Then
lblUploadResult.Text = strFilePath & " already exists on the server!"
Else
'Converts the uploaded to bitmap and saves it to the server
ConvertImage(strFileName, System.Drawing.Imaging.ImageFormat.Bmp, strFilePath)
lblUploadResult.Text = txtSaveAs.Text & ".bmp" & " has been successfully uploaded."
End If
End Sub