I want to access to the file on my web project under content folder, and I want to use relative path. Can someone confirm me that I'm using right approach
string file = System.Web.Hosting.HostingEnvironment.MapPath("~/Content/myfile.txt");
yes its 100% right. When you execute the code outside the context of a http request then HttpContext.Current is null and your code crashes. HostingEnvironment.MapPath always works
In this scenario i have used this approach to get multiple files and it worked fine ,so i recommend this . try it once
String[] files = Directory.GetFiles(@HostingEnvironment.ApplicationPhysicalPath + "\\Videos\\");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.