The Server.MapPath method maps the specified relative or virtual path to the corresponding physical directory on the server.
Questions tagged [server.mappath]
131 questions
133
votes
9 answers
Cannot use Server.MapPath
What I must do to make Server.MapPath work?
I have using System.Web;
what else? When I type Server there is no quick result option (intelli-sense) for Server.
Any help?

a1204773
- 6,923
- 20
- 64
- 94
130
votes
4 answers
How can I use Server.MapPath() from global.asax?
I need to use Server.MapPath() to combine some files path that I store in the web.config.
However, since Server.MapPath() relies on the current HttpContext (I think), I am unable to do this. When trying to use the method, even though its…

John B
- 20,062
- 35
- 120
- 170
125
votes
2 answers
Using Server.MapPath() inside a static field in ASP.NET MVC
I'm building an ASP.NET MVC site where I'm using Lucene.Net for search queries. I asked a question here about how to properly structure Lucene.Net usage in an ASP.NET MVC application and was told that the best method is to declare the my IndexWriter…

Maxim Zaslavsky
- 17,787
- 30
- 107
- 173
62
votes
7 answers
Server.Mappath in C# classlibrary
How can i use the server.mappath method in a C# class library class ,which acts as my BusinessLayer for My ASP.NET WEbsite

Shyju
- 214,206
- 104
- 411
- 497
41
votes
3 answers
Map the physical file path in asp.net mvc
I am trying to read an XSLT file from disk in my ASP.Net MVC controller. What I am doing is the following:
string filepath = HttpContext.Request.PhysicalApplicationPath;
filepath += "/Content/Xsl/pubmed.xslt";
string xsl =…

Phaedrus
- 793
- 1
- 10
- 17
23
votes
3 answers
Using Server.MapPath in MVC3
I have the code
string xsltPath = System.Web.HttpContext.Current.Server.MapPath(@"App_Data") + "\\" + TransformFileName
It returns
C:\inetpub\wwwroot\websiteName\SERVICENAME\App_Data\FileName.xsl
Why am I getting the path to the ServiceController,…

P.Brian.Mackey
- 43,228
- 68
- 238
- 348
21
votes
2 answers
How to use Server.MapPath when HTTPContext .Current is Nothing
I have some code that works fine when I need to delete some image files from a directory on my web server:
Dim ImageURL As String = dsImages.Tables(0).Rows(iImgRow).Item("ImageURL")
Dim physicalName =…

John Adams
- 4,773
- 25
- 91
- 131
19
votes
2 answers
Using MapPath from a worker thread
I have a WCF service method that's running in a worker thread I spin from another method. I need to map a relative service app path ("~/Templates/a.template") to the physical path ("D:\Web\Templates\a.template"), but I can't use…

Andrey
- 20,487
- 26
- 108
- 176
19
votes
4 answers
C# Unit Testing: Testing a method that uses MapPath
First of all, I am aware that this question is dangerously close to:
How to MapPath in a unit test in C#
I'm hoping however, that it has a different solution. My issue follows:
In my code I have an object that needs to be validated. I am creating…

Jeff
- 623
- 3
- 8
- 22
10
votes
3 answers
How can I use Server.MapPath inside class library project
I have a web application thet has a number of class library projects. Some example code below.
public static class LenderBL
{
static string LenderXml { get { return "MyPathHere"; } }
public static LenderColl GetLenders()
{
var…

dotnetnoob
- 10,783
- 20
- 57
- 103
9
votes
4 answers
An object reference is required for the non-static field, method, or property 'System.Web.UI.Page.Server.get'
So I have two functions and I'm getting an interesting problem. Essentially I'm aiming to make my code more portable in an easily includeable cs file.
Here's said cs file:
namespace basicFunctions {
public partial class phpPort : System.Web.UI.Page…
user798080
8
votes
6 answers
Get virtual path for a full path in asp classic
How can I get the virtual path for a full path in ASP classic. Note that the full path may be under a virtual directory and therefore the simplistic
virtPath = Replace(fullPath, Server.MapPath("/"), "")
method will not work.
Edit: To clarify, an…

C. Ross
- 31,137
- 42
- 147
- 238
8
votes
1 answer
HttpContext null in the Signalr Hub file
I have a SignalR hub. When the client disconnects, I want to perform a file operation.
To do that, I need to access the Server.MapPath.
However, as my Hub class is not an .aspx or a Web Service, there is no HttpContext nor request.
I thought of…

zaitsman
- 8,984
- 6
- 47
- 79
8
votes
4 answers
Use Server.MapPath in Business Layer
My business layer creates files and needs to save them in the App_Data folder of my asp.net mvc 4 web frontend.
I could use Server.MapPath in the business layer to get the physical path of the App_Data folder. But i want to avoid a reference to…

levis
- 125
- 1
- 1
- 6
8
votes
5 answers
In ASP.NET how you get the physcial file path when HttpContext.Current is NULL?
I'm working with DotNetNuke's scheduler to schedule tasks and I'm looking to get the physical file path of a email template that I created. The problem is that HttpContext is NULL because the scheduled task is on a different thread and there is not…

John
- 5,381
- 4
- 30
- 26