Search code examples
asp.net.netvb.netwebformsfilestream

Why the file stream is reading wrong path?


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.


Solution

  • 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