Hai
i have problem in delete file from folder,if i try to it show error like "unable to delete,this file used by another process"
First i download image file from sql server as bytes and save as image in folder using filestream and dispose and close filestream,after i will set background image for panel.if i again come same function it show error.so pl guid me how to remove background image and delete file from folder,so only i can again download from sql and save as image in folder
The below code for download from sql as bytes and save as image in folder(SLD in folder name)
Dim imageData As Byte() = Nothing
sqlCmd.Fill(dt)
For Each row In dt.Rows
imageData = DirectCast(row("SLD"), Byte())
SLDFileName = row("SLDFileName")
Next
Dim newImage As Image = Nothing
If Not imageData Is Nothing Then
Using ms As New MemoryStream(imageData, 0, imageData.Length)
ms.Write(imageData, 0, imageData.Length)
newImage = Image.FromStream(ms, True)
Dim fs As FileStream = File.Create(AppPath + "SLD\" + SLDFileName)
fs.Write(imageData, 0, imageData.Length)
fs.Dispose()
fs.Close()
End Using
ContainerSLD.BackgroundImage = Image.FromFile(AppPath + "SLD\" + SLDFileName)
End If
this below code for dispose and delete files from directory
If (Not ContainerSLD.BackgroundImage Is Nothing) Then
ContainerSLD.BackgroundImage.Dispose()
ContainerSLD.Dispose()
My.Computer.FileSystem.DeleteDirectory(System.Windows.Forms.Application.StartupPath + "\Diagram\SLD", FileIO.DeleteDirectoryOption.DeleteAllContents)
Else
End If
pls reply asap
Regards
Aravind