The Server.MapPath method maps the specified relative or virtual path to the corresponding physical directory on the server.
Questions tagged [server.mappath]
128 questions
125
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 Bubriski
- 18,881
- 34
- 115
- 167
121
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,149
- 30
- 100
- 167
118
votes
8 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,415
- 19
- 61
- 93
57
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
- 197,032
- 96
- 389
- 477
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
- 733
- 1
- 8
- 15
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
- 39,360
- 59
- 210
- 327
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
- 831
- 3
- 8
- 21
18
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,573
- 23
- 85
- 124
17
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
- 18,432
- 22
- 99
- 163
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
- 9,233
- 17
- 51
- 92
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
- 28,735
- 39
- 139
- 230
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
- 7,571
- 4
- 35
- 64
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,283
- 4
- 28
- 26