newid = Request.QueryString("newid")
If Not Page.IsPostBack() Then
Dim SelectCommand As String = "SELECT * FROM news WHERE newid = '" & newid & "' "
Dim da As New SqlDataAdapter(SelectCommand, conn)
da.Fill(ds, "select")
dt = ds.Tables("select").Rows(0)
lbldate.Text = dt("date")
txtTitle.Text = dt("title")
txtDetail.Text = dt("detail")
imgEdit.ImageUrl = "upload/" & dt("fileupload")
End If
End Sub
Protected Sub btnCon_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCon.Click
Dim UpdateCommand As String
Dim strfilename As String
If Trim(FileUpload1.FileName) = "" Then
strfilename = ""
Else
strfilename = FileUpload1.FileName
If Me.FileUpload1.HasFile Then
Dim intWidth, intHeight As Integer
Dim UiFileName, NewFileName As String
If FileUpload1.HasFile Then
UiFileName = Server.MapPath("upload/") & FileUpload1.FileName
If File.Exists(UiFileName) Then
File.Delete(UiFileName)
End If
FileUpload1.SaveAs(UiFileName)
intWidth = 100 '*** Fix Width ***'
intHeight = 0 '*** If = 0 Auto Re-Cal Size ***'
intHeight = 100
NewFileName = "upload/Thumbnail_" & FileUpload1.FileName
Dim objGraphic As System.Drawing.Image = System.Drawing.Image.FromFile(UiFileName)
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(Server.MapPath(NewFileName), objGraphic.RawFormat)
'*** Close ***'
objGraphic.Dispose()
End If
End If
End If
UpdateCommand = " UPDATE news " & _
" SET title ='" & txtTitle.Text & "'," & _
" detail ='" & txtDetail.Text & "'," & _
" fileupload ='" & strfilename & "'" & _
" WHERE newid =" & newid & ""
Dim com As New SqlCommand(UpdateCommand, conn)
With com
.Connection = conn
.CommandType = CommandType.Text
.CommandText = UpdateCommand
.ExecuteNonQuery()
End With
Response.Redirect("viewAddnews.aspx")
End Sub