2012-03-29 9 views
1

hye .... es ist dringend ... iam mit einem temporären Ordner zum Speichern von Bildern für die Vorschau und wenn ich versuche, sie zu speichern System.Runtime.InteropServices.ExternalException: Ein generischer Fehler in GDI + erreo aufgetreten ist berichtet ... Wenn FileUpload1.HasFile Dann Pfad Dim As String = Server.MapPath ("./ TempImages /") Dim oFileInfo As New Fileinfo (FileUpload1.PostedFile.FileName)System.Runtime.InteropServices.ExternalException: In GDI + ist ein allgemeiner Fehler aufgetreten. imp

 Dim fileName As String = oFileInfo.Name 

     Dim fullFileName As String = path + "\\" + fileName 
     Dim imagePath As String = "TempImages/" + fileName 

     If Not Directory.Exists(path) Then 
      Directory.CreateDirectory(path) 
     End If 

     FileUpload1.PostedFile.SaveAs(fullFileName) 
     Image1.ImageUrl = imagePath 

das ist, was Iam tun und speichern

Wenn (FileUpload1.HasFile) Dann Dim strextension As String = System.IO.Path.GetExtension (FileUpload1.FileName) If (strextension.ToUpper() = ".JPG") Dann

   Dim imagetoberezised As System.Drawing.Image = System.Drawing.Image.FromStream(FileUpload1.PostedFile.InputStream) 
       Dim imageheight As Integer = imagetoberezised.Height 
       Dim imagewidth As Integer = imagetoberezised.Width 
       Dim maxheight As Integer = 120 
       Dim maxwidth As Integer = 80 
       imageheight = (imagewidth * maxheight)/imageheight 
       imagewidth = maxheight 
       If imageheight > maxheight Then 
        imageheight = (imagewidth * maxheight)/imageheight 
        imagewidth = maxheight 


       End If 
       Dim bitmap As New Bitmap(imagetoberezised, imagewidth, imageheight) 
       Dim stream As System.IO.MemoryStream = New MemoryStream() 
       bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg) 
       stream.Position = 0 
       Dim img As Byte() = New Byte(stream.Length) {} 
       stream.Read(img, 0, img.Length) 
       Dim conn5 As New SqlConnection 
       conn5 = New SqlConnection 
       conn5.ConnectionString = "Server=aa-pc;Database=abcc;Uid=sa;[email protected];" 
       Try 
        conn5.Open() 
        Dim sql As String = "update abcset abc_IMAGE = @eimg where PART_NO=" & Val(Part_List.SelectedValue) 
        Dim cmd5 As SqlCommand = New SqlCommand(sql, conn5) 
        Dim uploadimage As New SqlParameter("@eimg", SqlDbType.Image, img.Length) 
        uploadimage.Value = img 
        cmd5.Parameters.Add(uploadimage) 
        Dim id As Integer = Convert.ToInt32(cmd5.ExecuteScalar()) 




       Catch 
        MsgBox("error") 

       Finally 
        conn5.Close() 

       End Try 

      End If 
     End If 

es funktioniert gut whilw wir es lokal, aber nicht auf dem Server ausgeführt werden ..

Antwort

0

die sie interessieren, ist es für mich arbeiten:

Dim path As String = Server.MapPath("~/TempImages") 

Dim FileInfo As New IO.FileInfo(FileUpload1.PostedFile.FileName) 
Dim fileName As String = FileInfo.Name 


'sets the image path 

Dim fullFileName As String = path + "\" + fileName 
Dim imagePath As String = "TempImages/" + fileName 

'If Not Directory.Exists(path) Then 

If Not System.IO.Directory.Exists("directory path") Then 
    System.IO.Directory.Exists("directory path") 
End If 

FileUpload1.PostedFile.SaveAs(fullFileName) 
Image1.ImageUrl = imagePath 
Verwandte Themen