When using the Task factory in ASP.net you will not be able to use the current HttpContext in the started task. Hence no HttpContext.Current.Server.MapPath(). To substitute this you can use System.Web.Hosting.HostingEnvironment.MapPath() instead.
A project I’m currently working on involves parsing a lot of HTML using the Html agility pack. One problem I came across was finding all heading level tags between 1 and 6 and here’s my solution using Xpath:
string xpathQuery = "//*[starts-with(name(),'h') and string-length(name()) = 2 and number(substring(name(), 2)) <= 6]"; var tags = htmlDocument.DocumentNode.SelectNodes(xpathQuery);
If someone has a better or alternative solution please let me know in the comments.