1
Protected Sub Upload_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Upload.Click
If Me.FileUpload1.HasFile Then
Dim intWidth, intHeight As Integer
Dim UlFileName, NewFileName As String
intWidth = 200 '*** Fix Width ***'
intHeight = 0 '*** If = 0 Auto Re-Cal Size ***'
'intHeight = 120
If Path.GetExtension(FileUpload1.FileName).ToLower <> ".gif" Then
'Pop Up. File needs to be a GIF
vLabel.Text = "Only .GIF files allowed. Please convert your image to a .GIF"
Else
UlFileName = "\\bk00app0001\Images\Temp_" & Me.ItemNumber.Text & "_" & Me.Year.Text & Path.GetExtension(FileUpload1.FileName).ToLower
'*** Save Images ***'
Me.FileUpload1.SaveAs(UlFileName)
NewFileName = "\\bk00app0001\Images\" & Me.ItemNumber.Text & "_" & Me.Year.Text & Path.GetExtension(FileUpload1.FileName).ToLower
Dim objGraphic As System.Drawing.Image = System.Drawing.Image.FromFile(UlFileName)
Dim objBitmap As Bitmap
'*** Calculate Height ***'
If intHeight > 0 Then
objBitmap = New Bitmap(objGraphic, intWidth, intHeight)
Else
If objGraphic.Width > intWidth Then
Dim ratio As Double = objGraphic.Height/objGraphic.Width
intHeight = ratio * intWidth
objBitmap = New Bitmap(objGraphic, intWidth, intHeight)
Else
objBitmap = New Bitmap(objGraphic)
End If
End If
'*** Save As ***'
objBitmap.Save(NewFileName, objGraphic.RawFormat)
'*** Close ***'
objGraphic.Dispose()
'*** Delete Original Image ***'
File.Delete(UlFileName)
'*** View Images ***'
Me.imgPicture.Visible = True
Me.imgPicture.ImageUrl = NewFileName
End If
End If
End Sub
圖片後上傳它沒有顯示在網頁上像它應該是:ASP.NET:圖片不顯示
'*** View Images ***'
Me.imgPicture.Visible = True
Me.imgPicture.ImageUrl = NewFileName
謝謝!
你能給的NewFileName'的'內容的文字的例子嗎?它看起來像一個網絡共享路徑,或者什麼,並且'Image'控件應該被提供一個URL,而不是一個物理文件路徑。 –
首先檢查圖片網址的有效性。 – Maysam
網絡共享路徑是「\\ bk00app0001 \ Images \ image.gif」我如何使這項工作? – Bruno