Esempio n. 1
0
    private void GetFilePath()
    {
        // 根据稿件ID或者流程日志ID得到稿件路径
        long CIDParam = 0;

        if (!string.IsNullOrEmpty(Request.QueryString["CID"]))
        {
            CIDParam = TypeParse.ToLong(Request.QueryString["CID"], 0);
        }
        // 日志ID
        long FlowLogID = 0;

        if (!string.IsNullOrEmpty(Request.QueryString["FlowID"]))
        {
            FlowLogID = TypeParse.ToLong(Request.QueryString["FlowID"], 0);
        }

        if (CIDParam > 0)
        {
            IContributionFacadeService cService = ServiceContainer.Instance.Container.Resolve <IContributionFacadeService>();
            // 得到稿件路径
            ContributionInfoQuery cQuery = new ContributionInfoQuery();
            cQuery.JournalID = SiteConfig.SiteID;
            cQuery.CID       = CIDParam;
            _filePath        = cService.GetContributionAttachment(cQuery);
        }
        else if (FlowLogID > 0)
        {
            IFlowFacadeService flowService = ServiceContainer.Instance.Container.Resolve <IFlowFacadeService>();
            // 附件路径
            FlowLogQuery logQuery = new FlowLogQuery();
            logQuery.JournalID = SiteConfig.SiteID;
            logQuery.FlowLogID = FlowLogID;
            _filePath          = flowService.GetFlowLogAttachment(logQuery);
        }

        if (!string.IsNullOrEmpty(Request.QueryString["fileName"]))
        {
            _fileName = Request.QueryString["fileName"];
        }
        else
        {
            _fileName = "在线审阅稿件";
        }
    }
Esempio n. 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            long CID = TypeParse.ToLong(Request.QueryString["CID"], 0);

            if (CID <= 0)
            {
                Response.Write("请选择正确的稿件");
            }
            IFlowFacadeService flowService = ServiceContainer.Instance.Container.Resolve <IFlowFacadeService>();
            // 附件路径
            FlowLogQuery logQuery = new FlowLogQuery();

            logQuery.JournalID = SiteConfig.SiteID;
            logQuery.FlowLogID = 0;
            logQuery.CID       = CID;
            string _filePath = flowService.GetFlowLogAttachment(logQuery);
            string fileName  = "";

            if (!string.IsNullOrEmpty(_filePath))
            {
                fileName = _filePath.Substring(_filePath.LastIndexOf("/") + 1);
            }

            string downPath = GetUploadPath(_filePath);

            if (!System.IO.File.Exists(downPath))
            {
                Response.Write("文件不存在");
            }
            if (!fileName.Contains("."))
            {
                fileName += Path.GetExtension(downPath);
            }

            IAuthorPlatformFacadeService service = ServiceContainer.Instance.Container.Resolve <IAuthorPlatformFacadeService>();
            ContributionInfoEntity       cEntity = service.GetContributionInfoModel(new ContributionInfoQuery {
                JournalID = SiteConfig.SiteID, CID = CID
            });
            string docTitle = "";

            if (cEntity != null)
            {
                docTitle = cEntity.Title + Path.GetExtension(downPath);
            }
            else
            {
                docTitle = fileName;
            }

            FileStream fs = new FileStream(downPath, FileMode.Open);

            //fs.Seek(0, SeekOrigin.Begin);
            byte[] bytes = new byte[(int)fs.Length];
            fs.Read(bytes, 0, bytes.Length);
            fs.Close();
            Response.ContentType = "application/octet-stream";
            //通知浏览器下载文件而不是打开
            Response.AddHeader("Content-Disposition", "attachment;  filename=" + docTitle);
            Response.AddHeader("Content-Length", bytes.Length.ToString());
            Response.ContentEncoding = Encoding.UTF8;
            Response.BinaryWrite(bytes);
            Response.Flush();
            Response.End();
        }