Questions tagged [mappath]
17 questions
66
votes
6 answers
Absolute path back to web-relative path
If I have managed to locate and verify the existence of a file using Server.MapPath and I now want to send the user directly to that file, what is the fastest way to convert that absolute path back into a relative web path?

tags2k
- 82,117
- 31
- 79
- 106
6
votes
1 answer
Get file inside views folder in ASP.Net MVC 4.0
I need to retrieve the name of a single view inside a views\something folder (comes from request) within MVC 4.0 and I'm not sure of how best to do it.
My code works but it has a 'hacky' feel to it and I was hoping someone could be simplified.
My…

davy
- 4,474
- 10
- 48
- 71
2
votes
1 answer
WCF getting the phisical path of URL adress
I'm new at WCF and i'm trying to create a service, it needs to convert url to server path. For example:
Gets -> "www.sample.com/client1"
Returns -> "c://samplefolder/sampleproject/client1"
I'm trying this code:
string realPath =…

Laura Jimenez
- 59
- 1
- 6
2
votes
2 answers
Classic ASP Server.MapPath() doesn't work as expected in global.asa
In Classic ASP, Server.MapPath() doesn't always work properly in the Application_OnStart event within global.asa. I have an ASP page at "\testfolder\test.asp" within a virtual root, I have an XSLT file at "\xsl\transform.xsl". My virtual root is…

andynormancx
- 13,421
- 6
- 36
- 52
2
votes
1 answer
httpcontext current server mappath shows c:\inetpub\wwwroot when the current location is somewhere else
I have taken on a MVC project, in VS 2008, from another developer and I need to know why HttpContext.Current.Server.MapPath("/") is c:\inetpub\wwwroot.
I am running the project from c:\Websites\Customer\Web\Website\Application\
IIS shows that the…

Jeremy Sanzone
- 73
- 8
1
vote
2 answers
Server.MapPath not accepting UNC URL
I'm having a bit of trouble loading an XML file with ASP.
This is the location of the XML file (it's a UNC url):
\\ilife104\teamdisk\Shared\Integration\System\dev\Data\prcImportFactSetFeeds\fileList.xml
And this is my code:
<%
'load the XML…
user179169
1
vote
1 answer
How to Load a file from another project of same solution
I have two projects in my solution, ProjectA and ProjectB. ProjectA contains folder named 'Config' which contains myfile.xml.
I want to access this file from ProjectB which is a WebAPI.
I tried following code:
string rootPath =…

Huma Ali
- 1,759
- 7
- 40
- 66
1
vote
2 answers
How do I get the ASP.NET content relative path
Doing a project between multiple people, and a few components (web app, services app and some others). We will be storing some information inside the Content folder of the web app so it can be accessed directly from the web server with an href,…

Cristiano Coelho
- 1,675
- 4
- 27
- 50
1
vote
2 answers
Server.MapPath gives error with UNC
Here is my directory to my server (permissions are good):
string ServerPath = ("\\\\servername\\Public\\Intranet2007Docs");
Here I am accessing it:
DirectoryInfo directory = new DirectoryInfo(Server.MapPath(ServerPath));
And here is the error:…

rainhider
- 49
- 1
- 4
- 13
0
votes
2 answers
Save file in a folder above the site files
My host has the following structure:
/Web -> Where is the content of the site
/Data -> Folder permissions to read and write
How do I upload a file to the Data folder?
The code below does not work, since "~" returns the directory / web.
//Save…

ridermansb
- 10,779
- 24
- 115
- 226
0
votes
1 answer
Make 'File Upload' optional in Upload Form - .NET
Right now, I'm using this to allow a file to be moved to our server:
filUpload.PostedFile.SaveAs(Server.MapPath("~/Images/" + filUpload.FileName));
However when I don't upload a file, it gives me an error:
System.IO.DirectoryNotFoundException: Could…

michaelmcgurk
- 6,367
- 23
- 94
- 190
0
votes
1 answer
Is there a way to map a path from an external server?
Well, I've been working on my server with a method like the following:
System.Web.HttpContext.Current.Server.MapPath("/path/something");
... and it's been working so far. Nevertheless, now I've encountered an issue. The thing is, I need to…

Jose Peres
- 197
- 1
- 1
- 18
0
votes
1 answer
How to MapPath in an IIS7 Rewrite Provider?
I am using the rather excellent IIS7 Rewrite module (V2), and want to create a custom RewriteProvider that rewrites differently depeneding on whether the physical file exists.
I have successfully created a provider, as in this…

Kram
- 4,099
- 4
- 39
- 60
0
votes
1 answer
Writing viewing stats to XML file. Possible problems with losing data count?
Hello I have created XML which holds codes for properties and number of page viewings for that code:
35

feronovak
- 101
- 1
- 6
0
votes
3 answers
Delete file on server
I have a file path in the format file://SERVERNAME/FOLDER$/FOLDER/image.jpg. I call System.IO.File.Delete(Server.MapPath(file://SERVERNAME/FOLDER$/FOLDER/image.jpg)) to delete the file, but i get the error file:/SERVERNAME/FOLDER$/FOLDER/image.jpg'…

jpo
- 3,959
- 20
- 59
- 102