//protected void rptSuccessStories_DataBound(object sender, RepeaterItemEventArgs e)
 //{
 //    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
 //    {
 //        SuccessStory s = e.Item.DataItem as SuccessStory;
 //        if (s != null)
 //        {
 //            if (s.HasPdfFile)
 //            {
 //                HyperLink b = rptSuccessStories.FindControl("hlPdfFile") as HyperLink;
 //                if (b != null)
 //                {
 //                    b.Visible = true;
 //                    b.Text = s.PdfFileName;
 //                }
 //            }
 //        }
 //    }
 //}
 protected void GetPdfFile(object sender, EventArgs e)
 {
     Erc.Apple.Data.SuccessStories ss = new Erc.Apple.Data.SuccessStories();
     SuccessStory sstory = ss.GetPdfFile(this.CurrentLanguage, this.GroupID);
     if (sstory != null && sstory.PdfFile != null && sstory.PdfFile.Length > 0 && !string.IsNullOrEmpty(sstory.PdfFileName))
     {
         Response.Clear();
         Response.AppendHeader("content-disposition", "attachment; filename=" + sstory.PdfFileName);
         Response.BinaryWrite(sstory.PdfFile);
         Response.Flush();
     }
 }
예제 #2
0
        public void ProcessRequest(HttpContext context)
        {
            string name = context.Request.QueryString["name"];
            string type = context.Request.QueryString["type"];
            string GroupID = context.Request.QueryString["groupid"];
            string Lang = context.Request.QueryString["lang"];
            if (!string.IsNullOrEmpty(name))
            {
                string filename = context.Server.MapPath(string.Format("~/files/{0}", name)).ToLower();
                string path = Path.GetDirectoryName(filename);
                if (filename.EndsWith(".pdf") && path.EndsWith("files") && File.Exists(filename))
                {
                    context.Response.Clear();
                    context.Response.ClearHeaders();

                    string attachment = String.Format("attachment; filename={0}", name);
                    context.Response.AddHeader("content-disposition", attachment);
                    context.Response.ContentType = "Application/pdf";
                    context.Response.AddHeader("Pragma", "public");

                    context.Response.WriteFile(filename);
                }
                else
                {
                    context.Response.Write("file not found");
                }
            }
            else if (!string.IsNullOrEmpty(type) && !string.IsNullOrEmpty(GroupID) && !string.IsNullOrEmpty(Lang))
            {
                switch (type)
                {
                    case "1":
                        Erc.Apple.Data.SuccessStories ss = new Erc.Apple.Data.SuccessStories();
                        try
                        {
                            SuccessStory s = ss.GetPdfFile(Lang, Int32.Parse(GroupID));
                            if (s != null)
                            {
                                string attachment = String.Format("attachment; filename={0}", s.PdfFileName);
                                context.Response.AddHeader("content-disposition", attachment);
                                //context.Response.ContentType = "Application/pdf";
                                context.Response.AddHeader("Pragma", "public");
                                context.Response.BinaryWrite(s.PdfFile);
                                context.Response.Flush();
                            }
                        }
                        catch (Exception)
                        {
                            context.Response.WriteFile("file not found");
                        }
                        break;
                    case "2":
                        Erc.Apple.Data.Stories sss = new Erc.Apple.Data.Stories();
                        try
                        {
                            Story st = sss.GetPdfFile(Lang, Int32.Parse(GroupID));
                            if (st != null)
                            {
                                string attachment = String.Format("attachment; filename={0}", st.PdfFileName);
                                context.Response.AddHeader("content-disposition", attachment);
                                //context.Response.ContentType = "Application/pdf";
                                context.Response.AddHeader("Pragma", "public");
                                context.Response.BinaryWrite(st.PdfFile);
                                context.Response.Flush();
                            }
                        }
                        catch (Exception)
                        {
                            context.Response.WriteFile("file not found");
                        }
                        break;
                }

            }
        }