How can i get the path of dlls when using Ninject binding? - path

My web app is in 'D:\WebApp folder' and there is a dll in 'D:\Bin' folder , I want to using ninject bindthe dll using the relative path instead of using the absolutely path 'D:\Bin' directly, since the absolutely path maybe changed somewhere.
the code like the following:
string path="how to get the path";
kernel.Bind(x => x.FromAssembliesInPath("path")
.SelectAllClasses()
.BindDefaultInterface());
How can i got the path in the code?

The path can be relative from the working dir e.g. "..\bin\the.dll". Make sure the path is in the probing path configuration of the application.

Related

How can I check the file exists in Network UNC path in ruby?

I have a text box where the user can type the UNC path like '\\server_name\testing\'
How can I check this UNC path exists?
I have tried lot of options from the File and Directory and did not get any clue.
My current code is
def get_files(path)
Dir.entries(path).select {|f| File.file?(f)}
end
When I tried to access get_files('\\server_name\testing\'). I got No such file or directory - No such directory: \\server_name\testing\
When I try to access through windows explorer it exists.
Thanks
Make sure your working directory is set properly, because your path will be considered relative to it. You can use Dir.pwd to get your working directory and Dir.chdir to change it.
\\server_name\testing is path to SAMBA resource, so you can't use standard ruby File IO.
Use smbclient to check path or sambal (wrapper around smbclient).

Setting correct path for libraries' resources in Chrome extension

If I use some external library when developing a Chrome extension, the relative paths for its resources are interpreted as relative to the current page, not the extension folder, which obviously result in a 404. Take CKEditor as an example:
GET http://www.mywebsite.com/mypage/config.js?t=F0RD
ckeditor.js:77
GET http://www.mywebsite.com/mypage/skins/moono/editor.css?t=F0RD
ckeditor.js:77
GET http://www.mywebsite.com/mypage/lang/pt-br.js?t=F0RD
ckeditor.js:220
Uncaught TypeError: Cannot set property 'dir' of undefined
What can be done to set the paths to the right place?
There is no "global" solution to my knowledge.
See if your library has a base bath config option. If it does not, you'll have to rewrite all paths to use chrome.runtime.getURL() (if possible) or a static version of that path.
For CKEditor in particular, this should help: Specifying the Editor Path
// Set this variable before loading CKEditor JS
// Replace "" with a subfolder if needed
var CKEDITOR_BASEPATH = chrome.runtime.getURL("");

Grails application root path

Is there a variable where I can find out the root directory of my Grails application?
for example, I have a folder named chart under \%root%\web-app\images\ where I put my charts in. Once I deploy my Grails application on Jetty, I will get FileNotFoundException because the root path becomes /srv/www/vhosts/domain-name/jetty-version/
I would like to know if there is a variable that returns the root path (like /srv/www/vhosts/domain-name/jetty-version/webapps/myapp), and there should be because CSS uses relative path just fine.
solved.
request.getSession().getServletContext().getRealPath("/")
this actually gives me the path to where my application puts the images, css, WEB-INF, etc. folders.
System.properties['base.dir']
I know it is an old question, but this could work if you are not in an http request:
ServletContextHolder.servletContext.getRealPath('/')
If you want to establish this is GSPs try this:
${createLink(uri: '/')}

Rails equivalent for MapPath (from ASP.NET)

Does Rails have an equivalent of the Server.MapPath method from ASP.NET? I've tried looking for one, but couldn't find anything.
Edit: I need this to generate a PDF with some images stored on the server. I know the relative path (URL) of the images, but I need an absolute path on disk to load them. I use FPDF for this and even though it says it accepts an URL, it doesn't seem to be the case (or I couldn't make it work).
It checked that it works with a hardcoded physical disk path and now I need to make it flexible.
Ruby has one: File.expand_path.
You can also use Rails.root to get the current path to rails project, then compose the path from there.
File.join(Rails.root, "public", "404.html")
File.expand_path("public/404.html", Rails.root)

Relative path of a given file from a service application in Delphi

I have a problem loading a file, as I'm passing a relative path to the function FileExists(Filename: String) and it's returning false, that is, it does not find the file in the directory that I pass.
I have a file named Template.html in the D:\Programming\Delphi\Projects\SendMail directory, and a service written in Delphi whose .EXE is in the D:\Programming\Delphi\Automation directory. I am passing the relative path: .\..\Projects\SendMail\Template.html to FileExists(), but it's returning that the file does not exist.
I think that has something to do with the relative path of a service and the relative path of the application being different. Can anybody help me with this?
As lorenzog said, try specifying the full path.
You can also try to set the currentdir to your likings.
//sets currentdir to your application.exe dir
SetCurrentDir(ExtractFileDir(ParamStr(0)));
You assume that the current directory of the service is the directory the executable is stored in. Call GetCurrentDir to find out the current directory.
My experience has been that services start with a working folder of %SystemRoot%\System32 no matter where the actual executable is located.
The way that I have got around this limitation is to write a registry key during installation of the service (e.g. HKLM\SOFTWARE\MyCompany\MyApp\INSTALL_PATH) that points to what I would like the working folder to be. Then when the service starts, it grabs the data from the registry and uses that value as the base when creating paths to files.

Resources