I have some file path like below for reaching the file:
StreamReader fileStream = new StreamReader(@"C:\Projects\SisStuff\SIS\SIS.Core\Models\CreateEditTemplate.cshtml");
now I want to remove the c:Project\SisStuff part to make it independent from file path in my computer, I tries @”~\Models\CreateEditTemplate.cshtml” but goes to find it in debug folder, how can I make it work?
The only way this would be able to work across systems is to build a known system variable. For example, you can get the Windows directory by using
%windir%right? Well that’s because it’s a well defined system variable.However, if you’re just trying to get to the root of your project you can remember that it is always going to start from the directory you’re executing from. So, while running in visual studio you would want (assuming you’re using the default path setup from the project templates)
..\..\Models\CreateEditTemplate.cshtml.However, if you needed this in production for some reason it would probably look more like
..\Models\CreateEditTemplate.cshtmlbecause by default there is simply abinfolder in production that you need to step up from.