Slette billede
HejJeg har oprettet et skema som jeg efterfølgende vil maile det en modtager.
Skemaet vises som en jpg fil vha screendump og alt fungerer fint MEN jeg vil programmeringsmæssigt kunne slette filen umiddelbart efter anvendelsen men når koden når til at slette så får jeg blot besked om at filen er i brug. Hvordan kan jeg slette den subsidiært evt anvende et screendump der ikke gemmes?
Private Sub EMail(ByVal Modtager As String, ByVal Tekst As String)
Dim D As DateTime = MonthCalendar1.SelectionRange.Start
'Lav screendump
Dim bmpScreenshot As Bitmap = New Bitmap(Width, Height, PixelFormat.Format32bppArgb)
Dim gfxScreenshot As Graphics = Graphics.FromImage(bmpScreenshot)
Dim TEMP As String
gfxScreenshot.CopyFromScreen(Me.Location.X, Me.Location.Y, 0, 0, Me.Size, CopyPixelOperation.SourceCopy)
bmpScreenshot.Save("F:\Temp\" & "Booking-" & D & ".jpg", ImageFormat.Jpeg)
Try
Dim smtpServer As New SmtpClient
Dim mail As New MailMessage
smtpServer.Credentials = New Net.NetworkCredential("XXXX@gmail.com", "XXXXX")
Dim contentID As String = "Booking for " & D
smtpServer.Port = 587
smtpServer.Host = "smtp.gmail.com"
smtpServer.EnableSsl = True
mail = New MailMessage
mail.From = New MailAddress("XXXX@gmail.com")
mail.To.Add(Modtager)
mail.Subject = "PH Varde procedurer for " & D
Dim attachment As System.Net.Mail.Attachment
attachment = New System.Net.Mail.Attachment("F:\Temp\" & "Booking-" & D & ".jpg")
mail.Attachments.Add(attachment)
mail.Body = Tekst
smtpServer.Send(mail)
Dim FileToDelete As String
FileToDelete = "F:\Temp\" & "Booking-" & D & ".jpg"
If System.IO.File.Exists(FileToDelete) = True Then
System.IO.File.Delete(FileToDelete)
MsgBox("File Deleted")
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub