Today Code , Copied to a C # class, and the compilation result is incorrect.
Database = server. mappath ("data. mdb ");
Error: The type or namespace name "server" cannot be found (whether the using command orProgramSet Reference ?)
But I did reference the namespace using system. Web. Why?
Because the complete path of the server is system. Web. httpcontext. Current. server. Using system. web is obviously not enough, but server can be directly written into the class inherited from the built-in page class. mappath "data. mdb "), it should be because the page class already contains these class paths.
the solutions to these errors are summarized as follows
1. Ensure that the correct assembly references:
ensure that the Assembly containing the namespace is referenced. If you are developing in Visual Studio. NET, go to the project menu and click Add reference. On the. NET tab, select the Assembly that contains the namespace you want to import, or browse to the folder that contains the assembly. If you are using the command line compiler, add the corresponding switch (/reference) to the compilation statement ).
2. Correct namespace:
(1) * If you execute this statement from the class inherited by the page class, you can simply use
database = server. mappath ("data. mdb ");
(2) if you are in a common class
A) Place the using statement at the top of the code file containing the type reference, make sure to import the namespace to the project:
using system. web;
database = httpcontext. current. server. mappath ("data. mdb ");
B) if there is no using statement, the reference to the type is fully Limited:
database = system. web. httpcontext. current. server. mappath ("data. mdb ");