I used code from here and I get the following error:
Can't use HttpContext.Current.Server.MapPath()
In Visual Studio 2008 does the ContextMenuEntry "Solve" help you when you have missing references?
I already found out that HttpContext
is not a member of System.Web
in my IDE.
According to Help > Info I am using .NET 3.5 SP1.
How do I get that running?
How do u usually react in this situation? What stuff do u look for in msdn.com?
When an HTTP request arrives at the server, the server processes the request and builds an HttpContext object. This object represents the request which your application code can use to create the response.
The object provides access to the intrinsic Request, Response, and Server properties for the request. This object is ready for garbage collection when the HttpRequest is completed.
HttpContext is not thread safe! No deadlocks if you block a Task with Task. Wait or Task.
What I would do in that situation is look on MSDN (or Google) for HttpContext
. I did that, and it says it’s in System.Web
. So make sure your project has a reference to System.Web
.
... and then it seems to work:
You can look in the documentation for the HttpContext class, and it tells you that it's in the System.Web
namespace, in the System.Web.dll
library.
So, to use it you need a reference to the System.Web.dll
library, and you either need a using System.Web;
statement, or use the fullly qualified name System.Web.HttpContext.Current.Server.MapPath
.
However, are you sure that you want to use the MapPath
method? The method gets the physical path of a web reference to a file. If the path to your CSV file is a web reference, for example "/data/items.csv"
then you want to use the MapPath
method, but if you have a physical path like for example "C:\mydata\items.csv"
then you don't want to convert it.
Also, the MapPath
only works if you actually are in a web application, where there is a HTTP context.
Timwi has it right, but for completeness. No, VS does not have the 'Solve' capability built in, however this functionality has been partially added by some add-ons. For example, Resharper will add the option to add the reference and using when needed -- but it does have to have been referenced before in the solution so it doesn't solve the initial find problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With