How to access Resouce [or other] files in custom plugin class

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
6 年 前
Hi, I'm new to nopcommerce.
I wan't to add some localization resources in Install method of my plugin and I want to read the resources from an XML file located in my plugin project. how can I access and read this files? how can i found the address? since I have no 'Server'!
totally how can i reach root folder of plugin inside plugin class isteslf.
pleeeeeaaaaaase help
6 年 前
Hello,

You can use something like this,

For Installing resource string while install method :-

  
protected virtual void InstallLocaleResources()
        {
          
            var language = _languageRepository.Table.Single(l => l.Name == "English");

          
            foreach (var filePath in System.IO.Directory.EnumerateFiles(_webHelper.MapPath("~/Plugins/PluginName/Localization/Installation"), "ResourceString.xml", SearchOption.TopDirectoryOnly))
            {
                var localesXml = File.ReadAllText(filePath);
                var localizationService = EngineContext.Current.Resolve<ILocalizationService>();
                localizationService.ImportResourcesFromXml(language, localesXml);
            }

        }



For UnInstalling resource string while uninstall method :-

Use same function but instead of calling
localizationService.ImportResourcesFromXml 
to load the xml string into a XML DOM object.

Then loop through all the LocaleResource elements, and with their Name attribute,

After call the usual
this.DeletePluginLocaleResource("pass-Name-here")
plugin method which commonly use.
6 年 前
You can also embed your files into plugin's assembly if you do not want to distribute your files together with the DLL. MSDN has great tutorial how to do that: https://support.microsoft.com/en-us/help/319292/how-to-embed-and-access-resources-by-using-visual-c
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.