コード例 #1
0
ファイル: ReportController.cs プロジェクト: olenake/Serene
        private ActionResult PrepareFileResult(IReport report, string ext, bool download,
                                               byte[] renderedBytes, ReportRegistry.Report reportInfo)
        {
            string fileDownloadName;
            var    customFileName = report as ICustomFileName;

            if (customFileName != null)
            {
                fileDownloadName = customFileName.GetFileName();
            }
            else
            {
                fileDownloadName = (reportInfo.Title ?? reportInfo.Key) + "_" +
                                   DateTime.Now.ToString("yyyyMMdd_HHss");
            }

            fileDownloadName += "." + ext;

            if (download)
            {
                return(new FileContentResult(renderedBytes, "application/octet-stream")
                {
                    FileDownloadName = fileDownloadName
                });
            }

            Response.Headers["Content-Disposition"] = "inline;filename=" + System.Net.WebUtility.UrlEncode(fileDownloadName);
            return(File(renderedBytes, KnownMimeTypes.Get(fileDownloadName)));
        }
コード例 #2
0
        /// <param name="mimeType">The mime type string, e.g. "application/json"</param>
        /// <returns>One or more extensions matching the mime type or null if no match</returns>
        public static string[] GetExtensions(string mimeType)
        {
            if (string.IsNullOrEmpty(mimeType))
            {
                throw new ArgumentNullException(mimeType);
            }

            return(KnownMimeTypes.LookupMimeType(mimeType));
        }
コード例 #3
0
ファイル: FilePage.cs プロジェクト: minhhungit/Serene
        public ActionResult Read(string pathInfo)
        {
            UploadPathHelper.CheckFileNameSecurity(pathInfo);

            if (!UploadStorage.FileExists(pathInfo))
            {
                return(new NotFoundResult());
            }

            var mimeType = KnownMimeTypes.Get(pathInfo);
            var stream   = UploadStorage.OpenFile(pathInfo);

            return(new FileStreamResult(stream, mimeType));
        }
コード例 #4
0
        /// <param name="file">The file extensions (ex: "zip"), the file name, or file path</param>
        /// <returns>The mime type string, returns "application/octet-stream" if no known type was found</returns>
        public static string GetMimeMapping(string file)
        {
            string fileExtension;

            if (file.Contains("."))
            {
                fileExtension = Path.GetExtension(file).Substring(1);
            }
            else
            {
                fileExtension = file;
            }
            string mimeType = KnownMimeTypes.LookupType(fileExtension.ToLowerInvariant());

            return(mimeType ?? UnknownMimeType);
        }
コード例 #5
0
        /// <param name="file">The file extensions (ex: "zip"), the file name, or file path</param>
        /// <returns>The mime type string, returns "application/octet-stream" if no known type was found</returns>
        public static string GetMimeMapping(string file)
        {
            if (file == null)
            {
                throw new ArgumentNullException(nameof(file));
            }

            if (string.IsNullOrEmpty(file))
            {
                return(UnknownMimeType);
            }

            var fileExtension = file.Contains(".")
                ? Path.GetExtension(file).Substring(1)
                : file;

            return(KnownMimeTypes.LookupType(fileExtension.ToLowerInvariant()) ?? UnknownMimeType);
        }