I have the following scenario in ASP.NET application:
Create a file in a temporary directory and return a link to that file.
I implement it as follows:
// get URL to create file
var tempDataOperationsDirectory = Server.MapPath("~/temp/DataOperations/foo1.txt");
// Create file
// Create link:
ButtonViewFile.NavigateUrl = Page.ResolveUrl("~/temp/DataOperations/foo1.txt");
The above works. I am wondering if that’s a good approach, and what if any alternatives are there?
It’s a good approach and also the recommended one. It will always generate an accurate link. Other approaches I can think of may not be as accurate as this one.