Today, I copied a code in webserice to a C # class and ran the compilation error.
DataBase = Server. MapPath ("data. mdb ");
Error:The type or namespace name "Server" cannot be found (is the using command or assembly reference missing ?)
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 solution to these errors is summarized as follows:
1. Ensure correct assembly references:
Make sure that the referenced assembly contains the namespace. 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
A) Place the using statement at the top of the code file containing the type reference, and ensure that the namespace is imported into 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 ");