0

I was wondering if there was an alternative to the System.IO.Directory.GetFiles Method that you could use for hosted websites. The problem is that this method uses the path starting from your drive, while it should only look for directories within the project.

It's to count the amount of images starting with a specific name, I have it setup, but without this method you would have to change values inside the code everytime you add or delete images, which is obviously something you do not want.

user6875529
  • 101
  • 9
  • You specify the path in the method. What's the problem? – gilliduck Jan 31 '18 at 13:21
  • The problem is that you're not guaranteed to have the same directories when the website is hosted. You cannot have for example D:\Projects\... on the host. – user6875529 Jan 31 '18 at 13:22
  • 1
    What's wrong with wrapping your calls to Directory.GetFiles in another method that handles this for you? Or using a pre-existing method that does this for you? Have you taken a look at `Server.MapPath`? – mason Jan 31 '18 at 13:22
  • 1
    @user6875529 why not use relative paths instead? No need to hardcode the path... – gilliduck Jan 31 '18 at 13:23
  • Yes, didn't think of such a way to recall file locations. I'm sure Server.MapPath will do the trick (didn't even know it existed). Ty for the suggestion. – user6875529 Jan 31 '18 at 13:27

0 Answers0