Since in "App_Code" you do not have an instance of the "HttpServerUtility" or "Server" object, you can pass it to your function and use it to translate site paths:
App_Code> Test.cs
using System.Web; public class Test { public static string getfile(HttpServerUtility Server ) { return Server.MapPath("~/Default.aspx"); } }
And when you call it from your ASPX pages, name it as:
string filepath = Test.getfile(Server);
Nasir source share