简体   繁体   中英

Why I can't use Server.MapPath() in my class?

I have the following problem when I try to call the Server.MapPath(); inside a class.

It give to me the following error message:

Error 3 The name 'Server' does not exist in the current context C:\\Develop\\EarlyWarning\\public\\Implementazione\\Ver2\\PdfReport\\iTextDocumentBase.cs 122 13 PdfReport

So I think that maybe I have to add the namespace related to the Server object but looking on the official documentation I can't found no related namespace: http://msdn.microsoft.com/en-us/library/ms525541%28v=vs.90%29.aspx

Why? What can I do to solve?

Tnx

在课堂上喜欢这样:

System.Web.HttpContext.Current.Server.MapPath("Relative path");

如果是网站,则可以使用以下代码访问.cs文件中的对象

string strPath = System.Web.HttpContext.Current.Server.MapPath("YourDesired Path");

Server is object in the Page class so you need to inherit the Page class or get through Page class object. You can use System.Web.HttpContext.Current.Server in you do not need to use Page class.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM