 |
|
อยากจะลบรูปที่อยู่ในFolder ก่อนที่จะอัพเดทอันใหม่เข้ามาคะ |
|
 |
|
|
 |
 |
|
อยากจะลบรูปที่อยู่ในFolder ก่อนที่จะอัพเดทอันใหม่เข้ามาคะ ช่วยดูให้ด้วยนะคะ ขอบคุณคะ
Code (VBScript)
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
Tag : .NET, Web (ASP.NET)
|
|
 |
 |
 |
 |
Date :
2010-09-04 09:57:18 |
By :
chokul |
View :
1071 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่ต้องเอารูปไปใส่ bitmap หรอกครับ
จะจัดการกับไฟล์ใช้ fileinfo ก็พอ
|
 |
 |
 |
 |
Date :
2010-09-04 16:23:46 |
By :
tungman |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ระวังเรื่อง FCN ค่ะ ถ้าจะมีการ ลบ แก้ไข หรือเพิ่มไฟล์ใน web app ของ ,net framework 2.0 up อะค่ะ
|
 |
 |
 |
 |
Date :
2010-09-04 17:00:53 |
By :
blurEyes |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|