0

I am trying to access textfile present in the folder inside the solution.

Dim fs As New FileStream("../CMMS/Webservices_URL.txt", FileMode.Open, FileAccess.Read)

but it always picks c drive even though the solution is somewhere else. why it's happening?

Folder1/Folder2/CMMS/Webservices_URL.txt is the actual path but it picks c:/CMMS.

avocadoLambda
  • 1,332
  • 7
  • 16
  • 33
Stacky
  • 29
  • 6
  • Remove the '../' – evry1falls Jun 14 '20 at 12:16
  • You probably want the [HttpServerUtility.MapPath(String) Method](https://learn.microsoft.com/en-us/dotnet/api/system.web.httpserverutility.mappath?view=netframework-4.8), and if it isn't happy about it then see [Cannot use Server.MapPath](https://stackoverflow.com/q/11105768/1115360). – Andrew Morton Jun 14 '20 at 14:40

1 Answers1

0

To get the physical path of a file in Web Forms you need to call Server.MapPath("~/Folder1/Folder2/CMMS/Webservices_URL.txt")

you can find the details here: https://learn.microsoft.com/en-us/dotnet/api/system.web.httpserverutility.mappath?view=netframework-4.8

NicoTek
  • 1,127
  • 1
  • 14
  • 34