I develop a module working with files. Serving the files in the themes using tilde is OK, but this doesn't seem to work in the controller, where I process the files with System.IO.File
methods like Move()
or Delete()
. For now I use absolute paths, but they are not feasible - the module should be used on different machines and still stored in a single repository.
How to find which root should I use for root-relaive paths in each situation? If there's no universal rule, how to find it while managing upload/download/viewing of files? Or is it more complicated?
My files are stored in: (SolutionRoot)/Orchard.Web/Media/Default/_FooBar/
I've tried all the folders as relative roots and it didn't work.
It seems to me that HostingEnvironment.MapPath
is probably what you are looking for.
If it isn't, then you can ask the executing assembly for its location and figure things out from there:
var codeBaseUrl = Assembly.GetExecutingAssembly().CodeBase;
var filePathToCodeBase = new Uri(codeBaseUrl).LocalPath;
var directoryPath = Path.GetDirectoryName(filePathToCodeBase);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.