Ejemplo n.º 1
0
        public object Get(DownloadPublicAttachment request)
        {
            bool   useAttachmentsRelativePath  = false;
            string sUseAttachmentsRelativePath = AppSettings.Get <string>("UseAttachmentsRelativePath");

            if (!string.IsNullOrWhiteSpace(sUseAttachmentsRelativePath) && bool.TryParse(sUseAttachmentsRelativePath, out bool bUseAttachmentsRelativePath))
            {
                useAttachmentsRelativePath = bUseAttachmentsRelativePath;
            }

            string strDirectory        = "Public";
            string strFileName         = request.FileName;
            string appSettingsFolder   = "Public";
            string baseAttachmentsPath = AppSettings.Get <string>(appSettingsFolder);

            string filePath;

            if (useAttachmentsRelativePath)
            {
                filePath = "~/" + baseAttachmentsPath + strDirectory + "/" + strFileName.MapHostAbsolutePath();
            }
            else
            {
                filePath = baseAttachmentsPath + strDirectory + "\\" + strFileName;
            }

            var file = new FileInfo(filePath);

            Log.Info($"Attachment Public Download: [{filePath}] by User: [{GetSession().UserName}]");

            return(new HttpResult(file, true)
            {
                Headers =
                {
                    [HttpHeaders.ContentDisposition] = $"inline; filename=\"{file.Name}\""
                }
            });
        }
Ejemplo n.º 2
0
        public object Get(DownloadPublicAttachment request)
        {
            bool   useAttachmentsRelativePath  = false;
            string sUseAttachmentsRelativePath = ConfigurationManager.AppSettings["UseAttachmentsRelativePath"];

            if (!string.IsNullOrWhiteSpace(sUseAttachmentsRelativePath) && bool.TryParse(sUseAttachmentsRelativePath, out bool bUseAttachmentsRelativePath))
            {
                useAttachmentsRelativePath = bUseAttachmentsRelativePath;
            }

            string strDirectory        = "Public";
            string strFileName         = request.FileName;
            string appSettingsFolder   = "Public";
            string baseAttachmentsPath = ConfigurationManager.AppSettings[appSettingsFolder];

            string filePath;

            if (useAttachmentsRelativePath)
            {
                filePath = "~/" + baseAttachmentsPath + strDirectory + "/" + strFileName.MapHostAbsolutePath();
            }
            else
            {
                filePath = baseAttachmentsPath + strDirectory + "\\" + strFileName;
            }

            var file = new FileInfo(filePath);

            return(new HttpResult(file, true)
            {
                Headers =
                {
                    [HttpHeaders.ContentDisposition] = $"inline; filename=\"{file.Name}\""
                }
            });
        }