.net CoreAPI 模板文件下载

[HttpGet("DownloadTemplate")]
        [AllowAnonymous]
        public async Task DownloadTemplate([FromQuery] EnumBackgroundConfig Config)
        {
            if (!Enum.IsDefined(typeof(EnumBackgroundConfig), (int)Config))
            {
                return Content("请求参数有误! ");
            }
            string EnumStr = Enum.GetName(typeof(EnumBackgroundConfig), (int)Config);
            if (string.IsNullOrEmpty(EnumStr))
            {
                return Content("请求参数有误! ");
            }
            var dir = $"{AppContext.BaseDirectory}TempFiles\\DownloadTemplate\\{EnumStr}.xlsx";
            dir = Freed.Common.Helpers.Utils.GetRuntimeDirectory(dir);
            if (!System.IO.File.Exists(dir))
                return Content("模板文件不存在! ");
            var ms = await System.IO.File.ReadAllBytesAsync(dir);
            return File(ms, "application/octet-stream", System.Web.HttpUtility.UrlEncode(EnumStr + ".xlsx"));
        }

你可能感兴趣的:(.Net,Core,.netcore)