Results 1 to 3 of 3

Thread: Server Error in '/' Application. Could not find a part of the path

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2018
    Posts
    17

    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/

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    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...

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width