Problems for loading local files in VB.NET code

laredo512

Well-known member
Joined
Jan 6, 2004
Messages
88
Location
Far enough to see snow in winter
I have the following error when trying this code:

Error :

ArgumentException: Invalid parameter used. at System.Drawing.Bitmap..ctor(String filename) at webapp.index.Upload_Click(Object Sender, EventArgs e) in C:\Documents and Settings\Administrator\VSWebCache\enterprise\index.aspx.vb:line 150

Line 150 refers to this line of code :

Dim to_bm As New Bitmap("c:\www\tester\logo.jpg")

What is my problem?!? I tried the same thing in a single file upload and no errors. Why does this not work now?

Thanks for any input.

e-mail: laredo512@yahoo.com

Code:
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        
        Dim MyPath, MyName As String
         Display the names in C:\ that represent directories.

        MyPath = "C:\www\tester"                       Set the path.
        MyName = Dir(MyPath, vbDirectory)    Retrieve the first entry.

        If MyName = "" Then    The folder is not there & to be created
            MkDir("C:\www\tester")       Folder created
            Span2.InnerHtml = "A Folder is created at the Page_Load"
        End If

    End Sub

    Sub Upload_Click(ByVal Sender As Object, ByVal e As EventArgs)
        Dim strResult As String
        Dim strFile As String
        Dim strFolder As String = "C:\www\tester"
        Dim objFile As HttpPostedFile
        Dim i As Integer

        Try
            For i = 0 To Request.Files.Count - 1
                objFile = Request.Files(i)

                Dim c As String = System.IO.Path.GetFileName(objFile.FileName.ToString)

                If Not (objFile Is Nothing Or objFile.FileName = "" Or objFile.ContentLength < 1) Then
                   
 Watermark each image and then save them

                    Dim fr_bm As Bitmap
                    Dim to_bm As New Bitmap("c:\www\tester\logo.jpg")

                    fr_bm = fr_bm.FromStream(objFile.InputStream)
                    to_bm.MakeTransparent(Color.Black)

                     Get a Graphics object for fr_bm.
                    Dim gr As Graphics = Graphics.FromImage(fr_bm)

                     Copy the image and a box around it.
                    Dim rect As New Rectangle( _
                       fr_bm.Width * 0.01, fr_bm.Height * 0.01, _
                      to_bm.Width, to_bm.Height)
                    gr.DrawImage(to_bm, rect)
                    gr.DrawRectangle(Pens.Transparent, rect)

                    Save the watermarked image and the original

                    fr_bm.Save("C:\www\tester\Water_file_" + c)
                    objFile.SaveAs("C:\www\tester\" + c)

                    Assign the File Name and File Type to Result
                    strResult = strResult & "Uploaded File: " & objFile.FileName & " of type " & objFile.ContentType & " <br> "
                    FileSize.InnerHtml = strResult
                End If
            Next

            If no files where selected provide a user friendly message
            If strResult = "" Then
                strResult = "Select atleast one file to upload."
                FileSize.InnerHtml = strResult
            End If

        Catch errorVariable As Exception
            Trap the exception
            strResult = errorVariable.ToString()
            FileSize.InnerHtml = strResult
        End Try

    End Sub
 
Back
Top