Using Directory.Getfiles with specifing the absolute path

前端 未结 3 1763
一向
一向 2021-01-13 14:17

Hi I wonder if you guys could help please.

I\'m writing a application that is going to live on multiple servers and therefore multiple IP\'s and instead of using the

相关标签:
3条回答
  • 2021-01-13 14:49

    In an ASP.Net application, you can call Server.MapPath("~/path") to resolve a path on disk relative to the application root directory.

    0 讨论(0)
  • 2021-01-13 15:14

    Use Path.GetFullPath to get the absolute path from your relative path.

    So, your code becomes:

    string[] filePaths = Directory.GetFiles(Path.GetFullPath(@"..\BlogEngine\"), "*.xml");
    
    0 讨论(0)
  • 2021-01-13 15:16

    Use the Server.MapPath() method to map a relative path (based on current directory or web-site root) to an absolute accessible path.

    For example:

    string folderPath = Server.MapPath("~/BlogEngine");
    string[] filePaths = Directory.GetFiles(folderPath, "*.xml");
    

    The tilde character represents the root of your web-site, if you specify a relative path then it'll be resolved as relative to the directory where your ASP.NET page resides.

    0 讨论(0)
提交回复
热议问题