• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 359
  • Last Modified:

Issues with Server.Mappath

Hello,

I am trying to use Server.Mappath in a Class library ( DLL Developed in C#).
After some research i found that i should be using the following command to get the Server path from the DLL.

System.Web.HttpContext.Current.Server.MapPath

I am using the following code

using System.Web;
using System.Web.UI;

String Filename;
Filename = System.Web.HttpContext.Current.Server.MapPath + "test.xml";

but I get this exception.
::Object reference not set to an instance of an object.

Your help will be appreciated.
Rithesh
0
Star79
Asked:
Star79
1 Solution
 
Daniel ReynoldsSoftware Applications Developer / IntegratorCommented:
A class would probably need to have the httpContext sent into it from the calling web page.

I suggest possibly adding a property of HttpContext type to pass it and then doing your mappath.
0
 
sabeeshCommented:
Filename = System.Web.HttpContext.Current.Server.MapPath("test.xml");

try like this
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now