Server Error in '/' Application. Could not find a part of the path
I'm trying to delete XML files on button click, the files are in the XML folder on my site (in smarterasp.net hosting) using this code :
Protected Sub Button4_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button4.Click
Dim directoryName As String = MapPath("~/xml/")
For Each deleteFile In Directory.GetFiles(directoryName, "*.xml", SearchOption.TopDirectoryOnly)
File.Delete(deleteFile)
Next
Label1.Text = "done"
End Sub
but I got this error :
Server Error in '/' Application.
Could not find a part of the path 'C:\Windows\SysWOW64\inetsrv\karary-001-
site1.htempurl.com\xml'.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.
Exception Details: System.IO.DirectoryNotFoundException: Could not find a
part of the path 'C:\Windows\SysWOW64\inetsrv\karary-001-
site1.htempurl.com\xml'.
Source Error:
An unhandled exception was generated during the execution of the current web
request. Information regarding the origin and location of the exception can
be identified using the exception stack trace below.
Stack Trace:
[DirectoryNotFoundException: Could not find a part of the path
'C:\Windows\SysWOW64\inetsrv\karary-001-site1.htempurl.com\xml'.]
what is right way to get the folder, I have tried those :
1- http://karary-001-site1.htempurl.com/xml/
2- h:\root\home\karary-001\www\site1\xml\
3- ~/xml/
Re: Server Error in '/' Application. Could not find a part of the path
You're using code that is intended for your local file system. I'm not sure how you'd delete xml files on your server, but it'll almost definitely need to be server side code...
Re: Server Error in '/' Application. Could not find a part of the path
You appear to be calling the MapPath method of a Page. I've never used that method so I'm not sure if it's different or not but most people tend to use Server.MapPath. Perhaps give that a try and see whether you get different results.