Relative path on console application - relative-path

I've an old program that use relative path to get mail templates.
The relative path point to local folder on the project folder .
My problem is that the program transalte the relative path to c:\windows\system32... .
The os is server 2008 .
There is any configuration work around that i need to do ?
Thanks in advance ,
Ishay .

You should use GetFullPathName function for converting relative path to full path, but pay attention YOU SHOULD NOT USE THIS FUNCTION IF YOUR PROGRAMM IS MULTITHREADED

Related

Error when trying to read a file via relative path in .net core 3.X in production

When I'm running my project in localhost I'm able to locate the file and process it further. This is achieved with this line of code.
path = Path.Combine(Directory.GetCurrentDirectory(), "EmailTemplates\\SuccessOrderWindows10.html");
I'm able to get the full relative path C:\etc\etc\etc.. But when i push this code to production, when it reaches to this stage, it throws an error
Error One or more occurred. (Could not find a part of the path 'h:\root\home\username\www\sitename\EmailTemplates\SuccessOrderWindows10.html'.)
What I'm doing wrong? Do i have to select the files and set them to content so that it will be included in the build?
Directory.GetCurrentDirectory will get the current working directory of the application.When you push the code to production,you change the the current working directory,so the relative path of your file will change,so you need to put the file to the new path h:\root\home\username\www\sitename\EmailTemplates\SuccessOrderWindows10.html when production.Or you can use absolute path.

Where should the files referred from GlassFish server 3.0 web app reside?

I have deployed my web application in GlassFish server 3.0. When I execute it, I get an error: The system cannot find the file specified (MobileOntologyRev1.owl) , which is a file from which I read in my code (I haven't specified the absolute path for this file in my code, and simply refer it using the file name without any addtional path) . Where should this file be kept in order to access it? I have presently tried keeping it inside the WEB-INF/Classes folder and in the root dir of the application inside glassfish/domains/domain1/
Where should I place this file??
You may consider taking advantage of the FaceContext as mentioned below.
You can create a folder (repors) inside your WEB-INF for example.
String pathToFile=
FacesContext.getCurrentInstance().getExternalContext().getRealPath("/WEB-INF/reports/MobileOntologyRev1.owl");

Laravel wrong public path file upload

I've deployed laravel with this guide.
http://juniorgrossi.com/deploying-laravel-applications-on-a-shared-host/
On my webserver I have a public_html file now containing all my publicly accesable files and a laravel folder containing the rest, so I've split up the default laravel structure for deployment.
On my development server by default the public folder is resting inside the laravel folder instead of being on the same directory level.
The problem I'm getting though is when I use something like this:
// Upload the file
Input::upload('image', 'public/uploads', $filename);
Same with this.
// Upload the file
Input::upload('image', path('public') . 'uploads', $filename);
Instead of trying to use the uploads folder that is inside my public_html folder it tries looking for a public file inside my laravel folder now.
And I get a
Unable to create the "/uploads" directory
Ofcourse on my development server the public folder is still inside the folder so it's logical.
How do I fix this?
You may try this (add a slash after the folder name)
Input::upload('image', path('public') . 'uploads/', $filename);
Maybe try this....just as a test
Input::upload('image', URL::to_asset('uploads/'), $filename);
You can also try
Intervention/image package.
I'm using this and I find it very easy to use. It also has a resize and crop feature.
It's easy as:
Image::make(Input::file('file')->getRealPath())->save('uploads/' . $filename);
Fixed the paths.php to ../public_html
I've done this before but it failed since I accidentaly uploaded a png and my jcrop function wich crops and saves images failed because it currently onlt takes jpg. So that left me thinking my paths.php settings were no good while they actually were.
Thanks for helping out though everybody!
(I feel like a fool.)
In my case, I got the same problem. Then I created it manually, CHMODed the lil' bastard and it worked fine!
Making a long history short (not so long...): just permission!
If you have the permission to Write/Read to the folder, you'll be cool! If you don't, you change the permissions! If you are unable to change it, put the uploaded files where the permissions allows you to access the file.

Using a dynamic drive letter alias for apache

I'm using XAMPP on my USB flash drive - which makes it easy for me to take my dev. environment with me from one PC to another.
However, I want to be able to serve files for my projects directly from my /Projects folder - which is in the root of the drive - instead of having to copy this folder into /htdocs.
I've read on the web that I can easily do this by adding an alias to 'httpd.conf' - but I would then need to hard-code the drive letter - which can be different for every PC I plug my USB into.
Is there any way to add a dynamic driver letter to my alias ?
Or - can I maybe use a relative path somehow ?
Or - am I going about it wrong and there's a better way to do it ?
Thanks in adv!
First of all, I think you already know that xampp lite supports relative addressing to run it in portable mod.
But when it comes to location of htdocs folder, I didnt experienced something like that. But I can offer some alternates (without moving the htdocs folder) which can be useful.
This simple .bat file (located in the same root of xampp folder)
#ECHO OFF
:START
Start xampp\htdocs
Can open your "htdocs" folder without depending to drive letter.
If you try to make something more complicated, here it comes the drive letter variable in .bat
#ECHO OFF
PUSHD \
SET AMOVIBLE=%CD%
POPD
ECHO %AMOVIBLE%
PAUSE
This example will show you the drive letter that the bat file executed from. Just move the %AMOVIBLE% variable wherever you want in your code.
And if variables from an external file is needed
Define variable
(SET /P var=)<sometextfile.txt
MKDIR folder\%var%\folder\
This can help.
So, if the movement of htdocs folder is not obligated, I think these will help. If not, sorry out of my range :)
Regards

Tell computer to use my dll files

I need to write a batch file which gets the path for a folder(e.g. lib) located in the current directory of the batch file and tell my computer to use my dll files located in there.
Anybody knows how to do this?
Thanks,
I have resolved the problem by changing the approach. Now I add my library into a given folder and then add its path to PATH environment variables by a batch file. Then run my exe file.