folder deleting not working

Go To StackoverFlow.com

1

If System.IO.Directory.Exists(HttpContext.Current.Server.MapPath("images/TravelogueGallery/" & getMaxID())) Then
    System.IO.Directory.Delete(HttpContext.Current.Server.MapPath("images/TravelogueGallery/" & getMaxID()), True)
End If

I am using the above code snippet to delete a directory but I get this error:

'G:\Projects\Latest\LTCIndia 05-04-12 1415\images\TravelogueGallery\19' is not a valid virtual path.

What's wrong with the code?

UPDATE: I have updated the question with the correct answer. The above code snippet works just fine. Thanks guys for your time.

2012-04-05 23:24
by user1150440
Remove the MapPath on the delete line. See if that helps - asawyer 2012-04-05 23:26
Possible duplicate of http://stackoverflow.com/questions/942514/is-not-a-valid-virtual-pat - Andrew Savinykh 2012-04-05 23:28
Check your relative path - coder 2012-04-05 23:29
ain't there any problem with the space caracter - Deblaton Jean-Philippe 2012-04-05 23:31
Fixed ...i had two Server.MapPath in the syntax HttpContext.Current.Server.MapPath(Server.MapPath(user1150440 2012-04-05 23:34
@user1150440 Please post the fix as an answer and (after the cooldown period) accept it, so the question appears answered when searched for - Dan J 2012-04-05 23:37
@DanJ Okie Doki - user1150440 2012-04-05 23:42


0

If System.IO.Directory.Exists(HttpContext.Current.Server.MapPath("images/TravelogueGallery/" & getMaxID())) Then
    System.IO.Directory.Delete(HttpContext.Current.Server.MapPath("images/TravelogueGallery/" & getMaxID()), True)
End If

This is the correct answer. I have updated the question with the correct answer. The above code snippet works just fine. Thanks guys for your time.

2012-04-05 23:47
by user1150440
Ads