Westwind.Globalization.DbResXConverter.ImportWinResources C# (CSharp) Method

ImportWinResources() public method

Imports Resources recursively from a non-Web project
public ImportWinResources ( string basePhysicalPath ) : bool
basePhysicalPath string The physical path to the directory
return bool
        public bool ImportWinResources(string basePhysicalPath)
        {
            if (basePhysicalPath == null)
                basePhysicalPath = BasePhysicalPath;

            // basePhysicalPath = basePhysicalPath.ToLower();
            if (!basePhysicalPath.EndsWith("\\"))
                basePhysicalPath += "\\";

            // We need to create a Web relative path (ie. admin/myresources.resx)
            string relPath = basePhysicalPath.Replace(BasePhysicalPath, "");
            relPath = relPath.Replace("\\", "/");

            // Import the base path first
            ImportDirectoryResources(basePhysicalPath, relPath);
            
            // Recurse into child folders
            string[] directories;
            try
            {
                directories = Directory.GetDirectories(basePhysicalPath);
            }
            catch
            {
                return false;
            }

            foreach (string dirString in directories)
            {
                DirectoryInfo directory = new DirectoryInfo(dirString);
                
                string dir = directory.Name;

                if (dir == "" || ("|bin|obj|.git|.svn|_svn|app_code|app_themes|app_data|migrations|node_modules|bower_components|".Contains("|" + dir.ToLower() + "|")))
                    continue;

                ImportWinResources(basePhysicalPath + dir + "\\");
            }

            return true;
        }

Usage Example

        protected void btnImport_Click(object sender, EventArgs e)
        {
#if OnlineDemo
        this.ErrorDisplay.ShowError(WebUtils.LRes("FeatureDisabled"));
        return;
#endif

            DbResXConverter Converter = new DbResXConverter(Context.Request.PhysicalApplicationPath);            
            
            bool res = false;

            if (DbResourceConfiguration.Current.ResxExportProjectType == GlobalizationResxExportProjectTypes.WebForms)
                res = Converter.ImportWebResources();
            else
                res = Converter.ImportWinResources(Server.MapPath("~/"));       

            if (res)
                ErrorDisplay.ShowMessage(WebUtils.LRes("ResourceImportComplete"));
            else
                ErrorDisplay.ShowError(WebUtils.LRes("ResourceImportFailed"));

            lstResourceIds.ClearSelection();
            lstResourceSet.ClearSelection();

            GetResourceSet();
        }