BExIS.Web.Shell.Areas.RPM.Controllers.DataStructureIOController.downloadTemplate C# (CSharp) Method

downloadTemplate() public method

public downloadTemplate ( long id ) : System.Web.Mvc.FileResult
id long
return System.Web.Mvc.FileResult
        public FileResult downloadTemplate(long id)
        {
            if (id != 0)
            {
                DataStructureManager dataStructureManager = new DataStructureManager();
                StructuredDataStructure dataStructure = new StructuredDataStructure();
                dataStructure = dataStructureManager.StructuredDataStructureRepo.Get(id);

                if (dataStructure != null)
                {
                    ExcelTemplateProvider provider = new ExcelTemplateProvider("BExISppTemplate_Clean.xlsm");
                    provider.CreateTemplate(dataStructure);
                    string path = "";

                    XmlNode resources = dataStructure.TemplatePaths.FirstChild;

                    XmlNodeList resource = resources.ChildNodes;

                    foreach (XmlNode x in resource)
                    {
                        if (x.Attributes.GetNamedItem("Type").Value == "Excel")
                            path = x.Attributes.GetNamedItem("Path").Value;

                    }
                    string rgxPattern = "[<>?\":|\\\\/*]";
                    string rgxReplace = "-";
                    Regex rgx = new Regex(rgxPattern);

                    string filename = rgx.Replace(dataStructure.Name, rgxReplace);

                    if (filename.Length > 50)
                        filename = filename.Substring(0, 50);

                    return File(Path.Combine(AppConfiguration.DataPath, path), "application/xlsm", "Template_" + dataStructure.Id + "_" + filename + ".xlsm");
                }
            }
            return File(Path.Combine(AppConfiguration.GetModuleWorkspacePath("RPM"), "Template", "BExISppTemplate_Clean.xlsm"), "application/xlsm", "Template_" + id + "_No_Data_Structure.xlsm");
        }
DataStructureIOController