Server.mappath always returns an absolute disk path to a file, regardless of if you pass a web path that starts from the root of the web or relative to the current directory.
chazukka's example will work fine as long as the script is executed from a page that's in the proper directory, i.e., a page that has subdirectory named database and the mdb file is in that subdirectory.
For example, assuming you're running /myweb/somewhere/myfolder/myasp.asp in a directory /myweb/somewhere/myfolder and the database file is in /myweb/somewhere/myfolder/database/mydb.mdb then
I just took up the task of learning ASP, done all the hello world stuff and then thought about the DB side of things and thought that a login system would be a nice place to start, so naturally I started with the registration page, and asp page to do the actual DB stuff, but it would seem I have a prob with Server.MapPath. So I edited my Register page to test and sure enough it doesn’t work, but it works when I make a page with just a .Write of the Server.MapPath Code:
where the querysting is something like "fname=this, that/this, that.xml".
I'm sure it's the comma, because if I remove it and rename the file and folder, everything works. I believe that a comma is a valid character in a folder or filename, so why does MapPath barf on it? Is there any way around this still using MapPath? Can someone point me to a source with a list of the valid characters the MapPath accepts?
I seem to be getting this error, and after Googling and searching this site, I still can't get a grip on it. I have a site on a server which is being developed for a national company who will offer this site to their members, hosting each on the national orgainzations servers. I have this string -
Which results in this error: The '..' characters are not allowed in the Path parameter for the MapPath method
Ok, the common solution seems to be a configuration on the server, which wouldn't be a problem IF the site was to remain where it is. BUT, seeing as I will give this site to the client, who will host it on their servers, could this configuration "fix" be a problem, perhaps for security issues.
well i m developing application in asp when i want to access these pages from ie5 it shows error HTTP Error 403 - Forbidden in internet explorer http://localhost/Mail/email.htm .
I thought this is more of an IE issue but i've had no joy on that group perhaps somebody here will have a clue.
If i click a link to a web page embedded in Excel (97 OR 2000) i get the standard error page displayed by IE (you know, the 'cannot find server or dns error' page).
Turning off 'show friendly http error messages' alleviates this. (Unfortunately this is the Windows default setting!)
Is there a built-in function that will give me the full url for a logically mapped address? Basically I want to pass "../folder1/default.asp" from www.mysite.com/folder2/something.asp and have it return "http://www.mysite.com/folder1/default.asp"...anyone know a nice way to do that? I'd like to avoid parsing the string if a function is already build in.
i've a legacy ASP.NTT code that works fine, but now i'm trying to add new feature. so i get the files from our source safe and put them in "d:ProjectsmySite" and created a new virtual directory for it and make it point to the project Directory.
till now every thing is ok, the problem is that Server.MapPath("/") returns "c:inetpubwwwroot" ? i dont know why, while it works fine on site. i'm running IIS 5 on win2000 pro.
Set objFile = objFSO.GetFile(Server.MapPath(strFileName))
this line brings up this error: ---------- Error Type: Microsoft VBScript runtime (0x800A0035) File not found /Turbomaster/presupuesto_confirm.asp, line 67 ------------ the variable strFileName is being read correctly..
there is an image folder in my root directoty containing images. When I run the following code from a file located in root directory, the file gets deleted. But when I put the file in some other folder, it generates error FILE NOT FOUND.
aND YES, i'VE TRIED BOTH fso.deletefile(server.mappath("Images/"&photo)) fso.deletefile(server.mappath("/Images/"&photo))
<% dim fso photo="902392.jpg" set fso = Server.CreateObject("Scripting.FileSystemObject") fso.deletefile(server.mappath("Images/"&photo)) %>
I am running exactly the same ASP code on IIS 5.0 and IIS 6.0
I am calling Server.MapPath(), the parameter is a virtual path that includes a reference to a parent path ("Root/Files/../Config/"). 'Config' is a virtual directory under 'Root' which is also a virtual directory. 'Files' is a normal folder.
Under IIS 5.0, the path is correctly mapped to the local path of the 'Config' virtual directory. Under IIS 6.0, the path gets mapped to "C:WebSiteRootFiles..Config", ignoring the 'Config' virtual directory mapping. Is there a special setting I should be aware of in IIS 6.0 to ensure correct mapping of virtual paths?
but then I create a new folder called for instance 'database' and move my diary.mdb into it(with full permissions), what do I change the server.mappath to?
The Windows OS allows commas in file/folder names but if you try to call .Code:
Server.MapPath("/smith, john/")
your application will neatly halt and provide you with an error report.Other than telling your site/network users not to use commas as allowed in the OS what can the application designer do to avoid the error.I am sure a kludgey workaround is to scan for the comma, change the file/folder name to something safe then restore the name at the end. I don't think this is a safe way to do things though.
I have a script: Set objdFile = Server.CreateObject("Scripting.FileSystemObject") Set OpendFile = objdFile.OpenTextFile(Server.MapPath("dUpdate.txt")) dFileValue = OpendFile.ReadLine OpendFile.Close
And It Returns A: "File Not Found Error"
The dUpdate.txt file is in the Root. what I am doing wrong?
I am coping a file from server to local on my computer using:
fso.CopyFile Server.MapPath("downloadworkfile.htm"), Server.MapPath("p:workingworkfile.htm"), true I am getting MapPath method must be a virtual path. How do I reference a virtual path?
I'm trying to create a log file of users accessing my site. This I can do on the current server using server.mappath, but I can't figure out how to write to a file on a different server.
I need to use Server.Execute for dynamic includes. My files are located in different folders and what works for one doesn't work for another. I need to include the full path to the file because relative paths do not work. Can someone tell me how to do something like this:
I have an asp file that gathers info from a form and sends to the database. im now changing the location of the database from the root path. I think that because of this i cannot use Server.MapPath method of sending data.
Coudl someone please help me out and let me know how i would change the code? Im quite new to this as you could probably see. Code:
In my root folder, there is a folder "Images". I need to check whether there is a file named 23.jpg in it or not. I am using the following code but it's returning false. The file is in the folder.
<% Set fs=Server.CreateObject("Scripting.FileSystemObject") x="23.jpg" If fs.FileExists(Server.Mappath("/Images/"&x)) = true Then Response.Write("File Exists.") Else Response.Write("File Does Not Exists") End If
I need to map a path to my database file automatically, if I move the application to a different direcotry level I still have to write part of the path to get the application to work.
Is there anyway I can translate the directory path and place inside the mappath function so I dont have to manually edit it?
I need to use Server.Execute for dynamic includes. My files are located in different folders and what works for one doesn't work for another. I need to include the full path to the file because relative paths do not work. Can someone tell me how to do something like this:
If I run Server.MapPath("/") on my operational Internet server I get, correctly, the physical path to the directory my page is in (d:.......htdocs).
If I run Server.MapPath("/") on my intranet server, my localhost, I get c:inetpubwwwroot, but my webpages are NOT in this folder, they are in c:webtest.
How to I establish the correct physical root on my intranet server?
How can I change a server.mappath back to the virtual path. I am creating a search function on my site and it search through the files on the server. I start with the server.mappath("/") and it searches through all the files just fine but the file path is displayed at d:sitefolderfile.asp. how can i change that path back to the virtual path (/folder/file.asp)?