get path to an included file on Classic ASP? - asp-classic

I have a file that is being included, in that file there's
Server.MapPath('../_data") which doesn't work
since that file included is not in the same Server.MapPath as the file executed.
any Idea of how I can get the included file's path?
To clarify the situation, I added a picture
As you can see, I'm including a file from one site to the other
(no other choice there), so that the server.mappath is intended to be different, though
the result is that on the included file I get the mappath of the executed file.

You should better use relative paths.
Relative paths start with / which means start from the root of the site..

Related

File Path and Root issues

So I have my the path to my website code as follows:
C:/folder1/folder2/folder3/my published website code from VS2012 - on my website I get an attachment and I want to save it to the following path C:/folder4
when I try the following code: file.SaveAs(Server.MapPath("../../folder4/") + filename); it says that I am going past the root. Can someone explain to me what is going on and if and how I can solve this issue?
Server.MapPath() is used to get the path in relation to the server root. Since your trying to save it outside the server virtual directory, you could probably just hardcode the file.
file.SaveAs(#"C:/folder4/" + filename);
It might not work depending on your IIS worker pool permissions.
file.SaveAs(Server.MapPath("folder4/") + filename);
Because I cannot see your folders structure I would reccomend setting a breakpoint after Server.MapPath() to see the full URI Path to determin your next steps since it says you are past root you may have one to many "../" before your string.
As per the documentation for HttpServerUtility.MapPath:
you cannot specify a path outside of the Web application
which is exactly what you are trying to do. If you interpret "the root" to be the root folder of your application, that is even what the error message is telling you.
Either
use an absolute path or
store your data beneath the application folder
use MapPath("~/") to get the current directory and build a relative path from that (in essence, you just move the "../.." outside the call to MapPath)
I would probably recommend going with 2. as it will give less headaches wrt. permissions and multiple sites hosted on the same server.
Server.MapPath(...) tries to return a physical ("real") directory for the virtual or relative path you give it. And since a virtual directory can't be located "over" the root in that sense, what you're trying to do makes no sense. You can go from domain.com/somefolder to domain.com/, but you can't really go any farther back.
You could instead use Environment.CurrentDirectoryas the starting point to find your folder, and apart from that just use SaveAs(..) as you're already doing.

DRUPAL 7 - Clean URL and relative path : it's doesn't work

I start with Drupal and I have read some of topics about my problem but I didn't found the solution.
My problem is the following :
On my website (for the moment in localhost) I use Clean URLS module. The problem is when I enable this module and when I use the relative path of my files, my pictures or links don't work.
For example : src="./sites/default/files/styles/large/public/add_tool_version.png".My pictures are not visibles.. I don't know why this module doesn't work with the relative path.
But when I disable the module, the link is works fine.
Please, can an you help me ? Do you have any solution to fix it ?
Thanks in advance for your answers
Try using absolute paths. In you case with image it would be like:
src="/sites/default/files/styles/large/public/add_tool_version.png", without dot.
This absolute path will always refers to that image instead of relative path - it depends on you current directory or page.
The problem with clean urls is the way browsers read urls and interpret them as directions in a file directory. Lets say you are at http://www.example.com/?q=node/11, or, with clean urls enabled, at http://www.example.com/node/11.
When enabeling clean urls, and putting a link with a source into some node, your browser will search for your files in the folder that is specified in your url. Thus, when you declare the source to be sites/default/files/styles/large/public/add_tool_version.png and are on the url http://www.example.com/node/11, then the browser will look for the file in the directory node/11/sites/default/files/styles/large/public/. Usually this would work, but in drupal, there actually is no such folder. All drupal pages are just versions of the index.php in your base-directory. In drupal, the url doesn't have anything to do with file structure - unfortunately, the average browser doesn't know that.
Without clean urls, however, your browser will recognize the url as a combination of a base path (www.example.com) and a query (?q=node/11). It will therefore look for your file starting from the directory specified in your base path.
If you still want to have your relative paths working with clean urls enabled, you can use the function base_path() in front of your actual source.

How to get exact path of servlet where it is running?

I have an application that I use in a servlet. The application assumes the text database residing in the same directory where it is being executed. When I am trying to use it in servlet and even after placing the text database files in /WebContent, /DataProject and also src folders. The application cannot find the database. I need to know exactly where the servlet file is being executed so I can place the database files in the same directory. I have already /.metadata/.plugin......../tmp0/wtpwebapps directory. Any help will be greatly appreciated.
Usually when we access files in java we give the absolute path. Dont use the relative path. We use relative paths for jsp/html/css etc. For accessing normal files use the complete path. So put the files in /home/tomcat/.../../directoryDatabase

FileHelpers file access

I am trying to get my head over FileHelpers library and have main critical problem. When I try to implement it in my web app, or even use online demo I end up with "FileNotFoundException". The chosen file is being looked for on my C: drive. How can I make the FileHelpers code to access relative path to my application instead of absolute one?
Regards,
Bartosz
Use the Server.MapPath() method to map a relative path (based on current directory or web-site root) to an absolute accessible path.
For example, if yourfile.txt is placed inside App_Data folder of your web-site then you can write:
Customer[] customers =
(Customer[])engine.ReadFile(Server.MapPath("~/App_Data/yourfile.txt"));
The tilde character represents the root of your web-site, if you specify a relative path then it'll be resolved as relative to the directory where your ASP.NET page resides.

Server.MapPath not returning expected path

I've been handed alegacy (Classic ASP), red headed step child who has been beaten, shot and otherwise maimed by a number of people before my time, application and for the life of me I can't figure out how it's actually working on production (I even got a copy from production just in case the files weren't up to date in source control).
I have code that does the following
tmpDefaultXSLFile="xsl/SomeValue"
...
objXsl.load(Server.MapPath(tmpDefaultXSLFile & ".xsl"))
However, Server.MapPath seems not to map the file to the expected location (i.e."\asp_file_directory\xsl\SomeValue.xsl" and the modification required is to the xsl file.
Is there ANY way that the system could be fooled into have Server.MapPath map somewhere else?
Looks like virtual directory on IIS is causing this. Check the URL and compare it to the directory structure within IIS including the virtual.
server.mappath(Path) specifies the relative or virtual path to map to a physical directory.
If Path starts with either a forward (/) or backward slash (\), the MapPath method returns a path as if Path is a full virtual path.
If Path doesn't start with a slash, the MapPath method returns a path relative to the directory of the .asp file being processed.

Resources