Save file in physical location of an orchard cms module - orchardcms

I'm developing an orchard module using visual studio 2013. I want to create a folder in my module folder, and create a text file in this folder.
I tried to get the physical path of my module in this way:
var areaName = HttpContext.Current.Request.RequestContext.RouteData.DataTokens["area"] as string;
var myFolderPath =
HttpContext.Current.Server.MapPath("/Modules/" + areaName + "/myFolder/");
Directory.CreateDirectory(myFolderPath);
But the value of mapped path in myFolderPath is C:\Users\myName\Documents\My Web Sites\Orchard.Web-Site\Modules\xxxArea\myFolder which is not the path of my orchard solution.
How can I get the physical location of my module correctly?

You likely want HttpContext.Current.Server.MapPath("~/Modules/" + areaName + "/myFolder/");Notice the tilde character at the beginning which makes it look at the root of your site.

Related

Media Library Child Folder Kentico 11

I need some assistance with media library Kentico 11.I have a Library with multiple folders inside, each folder has its own images.What I need is to get the direct path of a folder.My structure below, in this case i need the path for "Tops" so that i can pull all the images inside "Tops"
>Store(Folder)
>-Clothing(Folder)
> -Tops(Folder)
--images(File)
To get all images from the folder e.g. Store/Clothing/Tops
You can use something like:
var mediaFiles = MediaFileInfoProvider.GetMediaFiles()
.WhereStartsWith("FilePath", "Store/Clothing/Tops");
Depending on further requirements you can also add specific file types
.WhereEquals("FileExtension", ".png")
or select only from a specific media library
.WhereEquals("FileLibraryID", yourLibrary.LibraryID)
If you have access to the Database you can check the Database directly for how the paths are stored:
SELECT * FROM Media_File WHERE filepath LIKE 'Store/Clothing/Tops%'

Electron get data from custom extension file

I am using electron and trying to achieve a result where the user clicks on the saved file which opens the electron application and gets the data of the file.
So far I have done is:
1) Created the custom extension registry and added the file open command using reg file.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\.wtpd]
#="Water Treatment Plant Design File"
[HKEY_CLASSES_ROOT\.wtpd\DefaultIcon]
#="C:\\\\Users\\\\user\\\\Downloads\\\\wtpd_file.ico"
[HKEY_CLASSES_ROOT\.wtpd\shell]
[HKEY_CLASSES_ROOT\.wtpd\shell\open]
[HKEY_CLASSES_ROOT\.wtpd\shell\open\command]
#="\"C:\\Users\\user\\Desktop\\ENV\\electron.exe\" \"%1\""
2) Now it opens the electron application but i want to get the data inside of the .wtpd file in order to calculations.
I have tried to use this but the links in this examples are broken. https://www.theodo.fr/blog/2015/12/link-files-to-application-in-windows/
It seems that Windows passes the file path as an argument to the application (your Electron app in this case). So you can use process.argv to get the file path.
var filePath = process.argv[1];
var data = fs.readFileSync(openFilePath, 'utf-8');
Obviously you may want to add checks such as process.argv.length >= 2 to ensure the argument was passed (in case the application was opened manually, not invoked by windows). But this is generally how you could get the file contents.

How to embed, and get resources from Satellite Assembly In .NET MVC site for multiple locales

STEP 1: OK,I know I have read every page on the net about this so I finally broke down and ended up here at SOF.
Here is my resource file code:
using (ResourceWriter rw = new ResourceWriter(#"C:\pathto\errors.resources"))
{
rw.AddResource("String1", "en-US");
}
So obviously, now i have my errors.resources file created w/the string resource named String1, w/the value of "en-US" in it.
STEP 2: So then after that I simply create my satellite assembly with:
c:\>al /t:lib /culture:en-US /embed:C:\pathto\errors.resources /out:C:\pathto\bin\en-US\MyWeb.Ext.errors.resources.dll
Ok...so cool.
STEP 3: So now in my project:
Thread.CurrentThread.CurrentCulture = newCulture;
Thread.CurrentThread.CurrentUICulture = newCulture;
ResourceManager rm = new ResourceManager("MyWeb.Ext.errors", this.GetType().Assembly);
ViewData["String1"] = rm.GetString("String1");
But no matter what I do...I can not access that string resource in the assembly. I can include my errors.resources file in the project and get it that way, but I need it to be in this assembly so I can use this assembly for another project too!
Can someone tell me what I might be doing wrong on step 3?? Or maybe I did something wrong in a prior step??
Where is your resource file located relative to your assembly? You should create a directory containing the name of the locale the resource file is for (en-US in your case), and then place the satellite assembly in there. This directory should be in the same directory as the original assembly.

publishing MVC 4 app exception.., The specified path, file name, or both are too long

I am attempting to publish a website, using the file system method. I used this method with visual studio 2010 and I didn't run into to many problems. But I recieved the above error when trying in visual studio 2012. The full error is bellow...
Error : Copying file Service References\ACOServiceReference\FocusedReadMissionsRedux.ACOServiceReference.searchPatientbyDemographicsResponse.datasource to obj\Release\Package\PackageTmp\Service References\ACOServiceReference\FocusedReadMissionsRedux.ACOServiceReference.searchPatientbyDemographicsResponse.datasource failed. The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.
What am I missing or doing wrong? Obviously a file path is too long, but is there a way I can create like path variables or something to shorten the path names? How can I set that up?
No you can't shorten it as Windows will use the fully qualified name (C:\aaa\aaa...).
Two solutions:
Shorten your namespace (FocusedReadMissionsRedux.ACOServiceReference.searchPatientbyDemographicsResponse.datasource)
Change the location of your project (ie D:\Code\ProjectOne)
I was able to solve this problem on my project by navigating to the files under the service reference then under Reference.svcmap. Select each one of them and change the build action from Content to none. These files aren't usually needed for the app so they don't need to be published.

Load XML from Disk in C#

I am using C# test project .I wish to load a Xml which is available inside the project under a folder Dump . I am able to do
string path =
"C:\APP\FrameworkTest\TestProject\Dump\GetAddressById.xml";
but i don't want to use like this because if the drive changes,my code will fail.
in asp.net we have something like Server.MapPath() . Is there some thing like this ?
For example:
var dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var path = Path.Combine(dir, "Dump", "GetAddressById.xml")
Hope this helps.
If you know that folder Dump will always be present in the deployement folder of your application then you certainly don't need to hard code full path.
For ASP.net:
var path = System.IO.Path.Combine(Server.MapPath("/"), "Dump",
"GetAddressById.xml");
For C#:
var path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Dump",
"GetAddressById.xml");

Resources