Need Code to delete a file if file size is larger than 2 MBs
I have a watched folder for incoming pdf files. I need VB.Net code to delete any incoming file if the file size is larger than 2 MBs.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Kirtan PatelPosted Dec 17, 2009, 2:00 PM
Hirendra SisodiyaPosted Dec 17, 2009, 11:40 PM
Dim MyFile As New IO.FileInfo("C:\test.pdf")
Dim FileSize As Double = MyFile.Length / (1024 * 1024) 'Find file Size in Mb
If FileSize > 2 Then 'check test.pdf size is greter than 2 mb or not
MyFile.Delete() 'Delete file
End If
thank you
Tony WallacePosted Dec 16, 2009, 12:28 PM
Hiren SoniPosted Dec 16, 2009, 12:09 PM