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

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.

Related

I cannot install PhpWord Yii

I have tried to install PhpWord to yii. I have downloaded zip file and extracted it into extentions folder:
extenstions
--PHPWord
--PHPWord.php
However, I cannot make it to run. I got following error:
include(PHPWord.php): failed to open stream: No such file or directory
How can i solve it?
After extracting the file in extension folder, you have to import that file in controller.
Yii::import('ext.phpword.PHPWord');
First of all, you didn't say if it's Yii 1 or 2. They have different autoloading methods.
Second, you have extracted it into extension folder, and I assume your file where you want to include it is in a completely different folder.
You should do it like this
include('/full/path/to/PHPWord.php');
You need either absolute or a relative path to the file (I suggest using abosulte path (the one I used as an example).
Relative path means the path to the file you want to include compared to where your file, in which you are including it, is.

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");

Get the path to the current application in node-webkit

In node-webkit, is there any way to find the path to the current application? In node.js, you can use __dirname to find the path to the current application, but in node-webkit, the variable __dirname appears to be undefined.
The following node.js script prints the file path correctly:
console.log(__dirname)
The following node-webkit script does not print the file path correctly:
<script type = "text/javascript">
alert(__dirname);
</script>
What is the correct way to find the path to the current application in node-webkit?
The accepted answer's link is no longer available, so here is a short answer:
nw.js extract the content of your app, to a temp directory, every time you run it.
If you want to access the path where nw.js extracted your app, use process.cwd()
In other causes, where you want to access the path of your executable app, use:
var path = require('path');
var nwDir = path.dirname(process.execPath);
The answer to this question was discussed here: https://groups.google.com/d/topic/node-webkit/IwGzluFC9iU/discussion
On Windows, use "process.execPath" to see the path of the executable that launched it. Then work from there, removing the executable's filename from the path to get the folder's path (assuming your app's .nw is relative to the executable or is combined with it).
This works for me whether it is running with the zipped 'app.nw' or where 'nw.exe' and 'app.nw' are combined into one executable file (app.exe).
If you are looking for the path to the App source (i.e. the folder that contains package.json) then you can use process.cwd().
No matter what the environment's true working directory is when the node executable is launched, it will set process.cwd() to the location of the App source. If the App is contained in an archive, cwd will point to the temporary folder where the source is extracted.
Importantly, note that process.cwd() can be changed during the application run by process.chdir(newPath) and potentially by other events as well, so you might want to store the initial value at application launch.
EDIT:
Just to clarify, process.cwd() is set to the folder that contains the actual package.json file that is used by the running app. So if you have packaged your app in an archive or executable (zip, exe, nwz, nw, etc), then nw.exe will extract the project files to a temporary directory before running the app. So process.cwd() will point to that temporary folder, not the location of the original archive or executable.
this should work:
var nw = require('nw.gui'); //This line is only required for NW.js 0.12.x and below
console.log(nw.__dirname)
window.location won't work if you're loaded an external uri, but the following seems reliable regardless:
var path = require('path');
,appPath = path.dirname(require.main.filename)
Not sure when this is added, but I believe the official way to get the start up path now is:
nw.App.startPath

get package path from plug-in

I'm developing a plug-in, and I need to get a path of XML file that exist within java package, my question is how can I get the path of the file?
when i'm running the project as is i'm getting the file successfully but when i'm running the project as eclipse application the file located in anoter path.
any idea?
You can get every resource as InputStream with this line
this.getClass().getClassLoader().getResourceAsStream("/yourpackage/namefile");
Hope this help.

How can we access the files in the Data Folder when we publish the Vb.net application

I have added some files that I need to be downloaded to the Application start up path. So I set Build Action as content now the files have been copied some where
C:\Documents and Settings\TestUser.ANNAM\Local Settings\Apps\2.0\Data\HVDRBMY5.8AA\858AT9VM.TNP\test..tion_2d7cfc137d9c2c74_0001.0013_432bd4561850d290\Data
How can access file from the application. My problem since it is a dynamic path will it be same folder count so that we can use like ..\..\Data\ Some think like this
Application.UserAppDataPath gets the path for the application data of a user.
Application.StartupPath gives you the path for the executable file that started the application, not including the executable name.
Starting with one of these, you should be able to use System.IO to manipulate the paths until you get the folder where your data files are.