예제 #1
0
        /// <summary>
        /// 如果是可直接浏览文件格式,直接跳转
        /// </summary>
        /// <param name="fileID"></param>
        private void ImageDirect(string fileID)
        {
            fileID = fileID.ToLower();
            //如果附件为图片格式
            if (fileID.Contains(".jpg") || fileID.Contains(".png") || fileID.Contains(".gif"))
            {
                object fileBytes = null;
                string fileName  = FileStoreHelper.GetFileFullPath(fileID);
                if (fileName.LastIndexOf('.') > -1)
                {
                    var suffix = fileName.Substring(fileName.LastIndexOf('.') + 1).ToLower();

                    fileBytes = FileStoreHelper.GetFile(fileID);
                    if (fileBytes != null && fileBytes != DBNull.Value)
                    {
                        this.Response.Clear();

                        if (suffix == "jpg" || suffix == "png" || suffix == "gif")
                        {
                            this.Response.ContentType = "image/gif";
                            this.Response.OutputStream.Write(fileBytes as byte[], 0, ((byte[])fileBytes).Length);
                            this.Response.End();
                        }
                    }
                }
            }
        }
예제 #2
0
 public ActionResult ViewerPDF(string FileID)
 {
     ViewBag.IsExist = false;
     if (!System.IO.File.Exists(GetFileFullName(FixFileID(FileID))))
     {
         var sqlDb = Config.SQLHelper.CreateSqlHelper(Config.ConnEnum.FileStore);
         sqlDb.ExecuteNonQuery(string.Format("Update FsFile Set ConvertResult=null Where ID='{0}'", FixFileID(FileID)));
         ViewBag.IsExist = false;
         ViewBag.IsImg   = false;
         ViewBag.FileID  = FileID;
         string fileName = FileStoreHelper.GetFileFullPath(FileID);
         if (fileName.LastIndexOf('.') > -1)
         {
             var suffix = fileName.Substring(fileName.LastIndexOf('.') + 1).ToLower();
             if (suffix == "jpeg" || suffix == "bmp" || suffix == "gif" || suffix == "png" || suffix == "jpg")
             {
                 ViewBag.IsImg = true;
             }
             //ImageDirect(FileID);
         }
     }
     else
     {
         var filePath = "/MvcConfig/ViewFile/GetFile?FileID=" + FixFileID(FileID);
         ViewBag.FilePath = filePath;
         ViewBag.IsExist  = true;
     }
     return(View());
 }
예제 #3
0
        public FileResult GetImgFile(string fileID)
        {
            //string fileFullName = GetFileFullName(fileID);
            //byte[] swfFile = GetViewFile(fileFullName);
            fileID = fileID.ToLower();
            //如果附件为图片格式
            if (fileID.Contains(".jpeg") || fileID.Contains(".bmp") || fileID.Contains(".jpg") || fileID.Contains(".png") || fileID.Contains(".gif"))
            {
                string fileName = FileStoreHelper.GetFileFullPath(fileID);
                if (fileName.LastIndexOf('.') > -1)
                {
                    var suffix = fileName.Substring(fileName.LastIndexOf('.') + 1).ToLower();

                    byte[] fileBytes = FileStoreHelper.GetFile(fileID);
                    if (fileBytes == null)
                    {
                        throw new Formula.Exceptions.WebException("服务器上找不到浏览文件!");
                    }
                    if (fileBytes != null)
                    {
                        switch (suffix)
                        {
                        case "jpg":
                            return(File(fileBytes, "application/x-jpg/" + Path.GetExtension(fileName)));

                        case "png":
                            return(File(fileBytes, "application/x-png/" + Path.GetExtension(fileName)));

                        case "gif":
                            return(File(fileBytes, "image/gif/" + Path.GetExtension(fileName)));

                        case "jpeg":
                            return(File(fileBytes, "image/jpeg/" + Path.GetExtension(fileName)));

                        case "bmp":
                            return(File(fileBytes, "application/x-bmp/" + Path.GetExtension(fileName)));

                        default:
                            throw new Formula.Exceptions.WebException("文件格式不支持!");
                        }
                    }
                }
            }
            throw new Formula.Exceptions.WebException("文件格式不正确!");
        }