Exemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (Session["USER_GROUP"].ToString() == this.GuestUserID)
                {
                    string xScriptMsg = string.Format("<script>alert('사용권한이 없습니다.');window.location.href='/';</script>", Session["MENU_CODE"]);
                    ScriptHelper.ScriptBlock(this, "file_download_blob", xScriptMsg);

                    return;
                }

                Response.Buffer = true;

                string xKind     = Request["kind"];
                string xSeq      = Request["seq"];
                string xFseq     = Request["fseq"];
                string xFileName = Server.UrlDecode(Request["att_file_nm"]);

                byte[] xFile = (byte[])SBROKER.GetObject("CLT.WEB.BIZ.LMS.COMMON.vp_l_common_md",
                                                         "GetAttFile",
                                                         LMS_SYSTEM.OTHERS,
                                                         "CLT.WEB.UI.LMS.COMMON"
                                                         , xKind
                                                         , xSeq
                                                         , xFseq
                                                         );

                if (!Util.IsNullOrEmptyObject(xFile))
                {
                    Session.CodePage = 949;
                    Response.Charset = "UTF-8";

                    Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
                    Response.ContentType     = "Application/UnKnown";
                    Response.AppendHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(xFileName.Replace(" ", "_").Replace("..", "_")));
                    Response.BinaryWrite(xFile);
                }

                Response.End();
            }
            catch (Exception ex)
            {
                base.NotifyError(ex);
            }
        }
        public string SaveFile(string rFilename, string aa)
        {
            string xFilePath = string.Empty;

            try
            {
                string[] xParams = new string[2];
                xParams[0] = Request.QueryString["rseq"].ToString();
                xParams[1] = rFilename;

                object obj = null;
                obj = SBROKER.GetObject("CLT.WEB.BIZ.LMS.COMMUNITY.vp_y_community_notice_md",
                                        "GetNoticeFile",
                                        LMS_SYSTEM.COMMUNITY,
                                        "CLT.WEB.UI.LMS.COMMUNITY.edu_notice_detail", (object)xParams);


                byte[] fileByte = (byte[])obj;


                xFilePath = Server.MapPath("\\file\\tempfile\\") + rFilename;
                FileStream xNewFile = new FileStream(xFilePath, FileMode.Create);

                xNewFile.Write(fileByte, 0, fileByte.Length); // byte 배열 내용파일 쓰는 처리
                xNewFile.Close();                             // 파일 닫는 처리

                Response.Clear();

                FileInfo xfileinfo = new FileInfo(xFilePath);

                Response.Clear();
                Response.ContentType = "application/octet-stream";

                if (Request.UserAgent.IndexOf("MSIE") >= 0)  // InternetExplorer 일 경우
                {
                    /*
                     * 2013.08.20 Seojw
                     * 첨부파일 다운로드 시 스페이스에 "+"기호 붙는걸 방지하기 위해
                     * HttpUtility.UrlEncode → HttpUtility.HttpUtility.UrlPathEncode 로 변경
                     */
                    //Response.AppendHeader("Content-Disposition", String.Format("attachment; filename={0}", HttpUtility.UrlEncode(rFilename)));
                    Response.AppendHeader("Content-Disposition", String.Format("attachment; filename={0}", HttpUtility.UrlPathEncode(rFilename)));
                }
                else
                {
                    Response.AppendHeader("Content-Disposition", String.Format("attachment; filename={0}", HttpUtility.UrlDecode(rFilename)));
                }


                Response.TransmitFile(xfileinfo.FullName); //, 0, -1);
                Response.Flush();


                if (File.Exists(xFilePath))
                {
                    File.Delete(xFilePath);
                }

                Response.End();
            }
            catch (Exception ex)
            {
                bool rethrow = ExceptionPolicy.HandleException(ex, "Propagate Policy");
                if (rethrow)
                {
                    throw;
                }
            }
            return(xFilePath);
        }
Exemplo n.º 3
0
        /************************************************************
         * Function name : btnDown_Click
         * Purpose       : File Download 버튼 Click 이벤트
         * Input         : void
         * Output        : void
         *************************************************************/
        protected void btnDown_Click(object sender, EventArgs e)
        {
            try
            {
                Button btnDown         = (Button)sender;
                string xTextBookId     = string.Empty;
                string xTextBookFileNm = string.Empty;
                object obj             = null;

                for (int i = 0; i < this.dtlText.Items.Count; i++)
                {
                    Button xtemp = ((Button)this.dtlText.Items[i].FindControl("btnText"));
                    if (btnDown.UniqueID == xtemp.UniqueID)
                    {
                        xTextBookId     = ((Label)this.dtlText.Items[i].FindControl("lblTextbookid")).Text;
                        xTextBookFileNm = ((Label)this.dtlText.Items[i].FindControl("lblTextbookFileNm")).Text; //

                        obj = SBROKER.GetObject("CLT.WEB.BIZ.LMS.MYPAGE.vp_p_study_md",
                                                "GetStudyTreeTextFile",
                                                LMS_SYSTEM.MYPAGE,
                                                "CLT.WEB.UI.LMS.MYPAGE", xTextBookId);
                        byte[] fileByte = (byte[])obj;

                        string     xFilePath = Server.MapPath("\\file\\tempfile\\") + xTextBookFileNm;
                        FileStream xNewFile  = new FileStream(xFilePath, FileMode.Create);

                        xNewFile.Write(fileByte, 0, fileByte.Length); // byte 배열 내용파일 쓰는 처리
                        xNewFile.Close();                             // 파일 닫는 처리

                        Response.Clear();

                        FileInfo xfileinfo = new FileInfo(xFilePath);

                        Response.Clear();
                        Response.ContentType = "application/octet-stream";

                        if (Request.UserAgent.IndexOf("MSIE") >= 0)  // InternetExplorer 일 경우
                        {
                            /*
                             * 2013.08.20 Seojw
                             * 첨부파일 다운로드 시 스페이스에 "+"기호 붙는걸 방지하기 위해
                             * HttpUtility.UrlEncode → HttpUtility.HttpUtility.UrlPathEncode 로 변경
                             */
                            //Response.AppendHeader("Content-Disposition", String.Format("attachment; filename={0}", HttpUtility.UrlEncode(xTextBookFileNm)));
                            Response.AppendHeader("Content-Disposition", String.Format("attachment; filename={0}", HttpUtility.UrlPathEncode(xTextBookFileNm)));
                        }
                        else
                        {
                            Response.AppendHeader("Content-Disposition", String.Format("attachment; filename={0}", HttpUtility.UrlDecode(xTextBookFileNm)));
                        }

                        Response.TransmitFile(xfileinfo.FullName); //, 0, -1);
                        Response.Flush();

                        if (File.Exists(xFilePath))
                        {
                            File.Delete(xFilePath);
                        }

                        //Response.End();
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }