Tuesday, March 13, 2012

Server.MapPath >> Path from my web application

Hi,

I would like to get path from my web application :

exemple : C:\InitPub\www\webApplication1\

When I use in my code behind :

string path =ClassXml.GetValueFromKeyGeneric( Server.MapPath("XML/XMLFile_Config.xml"),"/configs/configs","PATHWEBSITE");

it's work,

But when I use this in my class in App_Code , I have this mistake : Error 115 The name 'Server' does not exist in the current context

Since your class does not derive from System.Web.UI.Page, it does nothave access to the 'Server' shortcut. UseSystem.Web.HttpContext.Current.Server.MapPath() instead.

When I useSystem.Web.HttpContext.Current.Server.MapPath(".")

I have this message :
Compiler Error Message:CS0134: 'ClassConstante.PATHNOVAGATE' is of type 'string.' A const of reference type other than string can only be initialized with null


Hello,

I change my string by :

string path = System.Web.HttpContext.Current.Server.MapPath("Default.aspx");

But I have always errors :

{"Object reference not set to an instance of an object."}


is Default.aspx in the same folder as the call? Try with a "." instead once, and see what folder it gives you...

0 comments:

Post a Comment