Last post Sep 01, 2020 02:48 AM by yij sun
Aug 31, 2020 05:52 PM|yzidell|LINK
i trying to delete a file on my server, but the file is still there after this runs
here is my code:
dim strInvitationInsideGenericFileName as string = "C:\Inetpub\wwwroot\MyLabels\EmailAttachments\Invitation_Outside_EventID_182.pdf"
If System.IO.File.Exists(strInvitationInsideGenericFileName) = True Then
thx for ur help
Aug 31, 2020 06:05 PM|PatriceSc|LINK
Basic debugging. I would except Delete to throw an exception if the file can"t be deleted. If you dont hide exceptions it could mean that for some reason
System.IO.File.Exists(strInvitationInsideGenericFileName) really returns false (maybe because of an hard to spot difference such as maybe having __ rather than _ in the actual file?. It could be also that this file is deleted and then created again there
In short even for a couple of lines, you should rather use the debugger to see what your code does exactly and then fix that rather than wondering what could happen from your code. As you see you can often find multiple possible problems nbut then
you have no way to know which one actually happens.
Sep 01, 2020 02:48 AM|yij sun|LINK
Accroding to your codes,as far as I think,you could check follow this:
1.Make sure the ASP user has permissions to this folder. By default this user is not given access to much of the harddrive.
2.Make sure the file's path is right.
I suggest you could debug and breakpint to check wheather your codes are right and have no errors.
This is a demo:
Public Sub DeleteFileFromFolder(ByVal StrFilename As String)
Dim strPhysicalFolder As String = Server.MapPath("..\")
Dim strFileFullPath As String = strPhysicalFolder & StrFilename
If IO.File.Exists(strFileFullPath) Then
If you have errors and can't solve it by yourself,you could post your errors and full codes to us.It will help us to solve your problems.