protected void DeleteButton_Click(object sender, ImageClickEventArgs e) { //Get the reference of the clicked button. ImageButton button = (sender as ImageButton); //Get the command argument string commandArgument = button.CommandArgument; int wishlistid = int.Parse(commandArgument); GalleryEntities1 db = new GalleryEntities1(); var item = new WISHLIST { WishlistId = wishlistid }; db.Entry(item).State = EntityState.Deleted; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { ModelState.AddModelError("", String.Format("Item with id {0} no longer exists in the database.", wishlistid)); } }
protected void btnAddToCart_Click(object sender, EventArgs e) { //Get the reference of the clicked button. Button button = (sender as Button); //Get the command argument string[] commandArgument = button.CommandArgument.ToString().Split(';'); int wishlistId = Convert.ToInt32(commandArgument[0]); int productId = Convert.ToInt32(commandArgument[1]); //System.Diagnostics.Debug.WriteLine(wishlistId + "," + productId); ShoppingCart sc = new ShoppingCart(); sc.AddToCart(productId); GalleryEntities1 db = new GalleryEntities1(); var item = new WISHLIST { WishlistId = wishlistId }; db.Entry(item).State = EntityState.Deleted; try { db.SaveChanges(); Response.Redirect("~/Wishlistaspx.aspx"); } catch (DbUpdateConcurrencyException) { ModelState.AddModelError("", String.Format("Item with id {0} no longer exists in the database.", wishlistId)); } }
protected void Page_Load(object sender, EventArgs e) { MembershipUser u; u = Membership.GetUser(User.Identity.Name); Guid key = (Guid)u.ProviderUserKey; String keyString = key.ToString(); TextBox address = (TextBox)FormViewPayment.FindControl("txtboxAddress"); GalleryEntities1 _db = new GalleryEntities1(); if (Roles.IsUserInRole("Artists")) { artist = _db.ARTISTs.Find(key); address.Text = artist.Address; } else { customer = _db.CUSTOMERs.Find(key); address.Text = customer.Address; } //address.Text = u.a TextBox email = (TextBox)FormViewPayment.FindControl("txtboxEmail"); email.Text = u.Email; email.Enabled = false; Session["email"] = email.Text; double total1 = Convert.ToDouble(Session["total"]); TextBox txtboxTotal = (TextBox)FormViewPayment.FindControl("txtboxTotal"); txtboxTotal.Text = String.Format("{0:0.00}", total1); }
public void Dispose() { if (_db != null) { _db.Dispose(); _db = null; } }
protected void CreateUserWizard1_CreatedUser(Object sender, EventArgs e) { MembershipUser newUser = Membership.GetUser(CreateUserWizard1.UserName); Guid newUserId = (Guid)newUser.ProviderUserKey; string Name = ((TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("Name")).Text; string Address = ((TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("Address")).Text; string Contact = ((TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("Contact")).Text; DropDownList ddlYear = (DropDownList)CreateUserWizardStep1.ContentTemplateContainer.FindControl("Year"); DropDownList ddlMonth = (DropDownList)CreateUserWizardStep1.ContentTemplateContainer.FindControl("Month"); DropDownList ddlDay = (DropDownList)CreateUserWizardStep1.ContentTemplateContainer.FindControl("Day"); Int32 day = Int32.Parse(ddlDay.SelectedValue); Int32 month = Int32.Parse(ddlMonth.SelectedValue); Int32 year = Int32.Parse(ddlYear.SelectedValue); Int32 Age = DateTime.Now.Year - year; DateTime DOB = new DateTime(year, month, day); DropDownList registerAs = (DropDownList)(CreateUserWizardStep1.ContentTemplateContainer.FindControl("registerAs")); String value = registerAs.SelectedValue; using (SqlConnection myConnection = new SqlConnection(connectionString)) { SqlCommand mycommand = null; if (value.Equals("Members")) { mycommand = new SqlCommand("new_user", myConnection); } else { mycommand = new SqlCommand("new_artist", myConnection); } mycommand.CommandType = System.Data.CommandType.StoredProcedure; mycommand.Parameters.Add("Name", SqlDbType.VarChar).Value = Name; mycommand.Parameters.Add("Address", SqlDbType.VarChar).Value = Address; mycommand.Parameters.Add("DateOfBirth", SqlDbType.Date).Value = DOB.Date; mycommand.Parameters.Add("UserId", SqlDbType.UniqueIdentifier).Value = newUserId; mycommand.Parameters.Add("Age", SqlDbType.Int).Value = Age; mycommand.Parameters.Add("Contact", SqlDbType.VarChar).Value = Contact; myConnection.Open(); mycommand.ExecuteNonQuery(); myConnection.Close(); Roles.AddUserToRole(CreateUserWizard1.UserName, value); } GalleryEntities1 _db = new GalleryEntities1(); CART cart = new Models.CART(); cart.UserId = newUserId; cart.Date = DateTime.Now; cart.Discount = 0; _db.CARTs.Add(cart); _db.SaveChanges(); HttpContext.Current.Session["CartId"] = cart.CartId; }
public static List <String> GetProductName(string pre) { List <string> allProductName = new List <string>(); using (GalleryEntities1 db = new GalleryEntities1()) { allProductName = (from a in db.PRODUCTs where a.Name.Contains(pre) select a.Name).ToList(); } return(allProductName); }
protected void btnWishlist_Click(object sender, EventArgs e) { bool loginStatus = (System.Web.HttpContext.Current.User != null) && System.Web.HttpContext.Current.User.Identity.IsAuthenticated; if (loginStatus) { GalleryEntities1 _db = new GalleryEntities1(); int productID = Convert.ToInt32(Request.QueryString["ProductID"]); Guid userId = (Guid)Membership.GetUser().ProviderUserKey; var existingItem = from w in _db.WISHLISTs where w.ProductId == productID && w.UserId == userId select w; if (existingItem.Any()) { successAdd.Style["display"] = "none"; failedAdd.Style["display"] = "block"; System.Diagnostics.Debug.WriteLine("exist"); } else { WISHLIST item = new WISHLIST(); item.ProductId = productID; item.UserId = userId; if (ModelState.IsValid) { // Save changes here _db.WISHLISTs.Add(item); _db.SaveChanges(); successAdd.Style["display"] = "block"; failedAdd.Style["display"] = "none"; } System.Diagnostics.Debug.WriteLine("not exist"); } } else { MasterPage masterPage = this.Master as MasterPage; ModalPopupExtender ModalPopupExtender1 = (ModalPopupExtender)masterPage.FindControl("ModalPopupExtender1"); ModalPopupExtender1.Show(); } }
protected void Page_Load(object sender, EventArgs e) { u = Membership.GetUser(User.Identity.Name); _db = new Models.GalleryEntities1(); Guid key = (Guid)u.ProviderUserKey; String keyString = key.ToString(); if (Roles.IsUserInRole("Artists")) { artist = _db.ARTISTs.Find(key); } else { customer = _db.CUSTOMERs.Find(key); } for (int i = 2003; i >= 1950; i--) { ListItem item = new ListItem(i + "", i + ""); ddlYear.Items.Add(item); } if (!IsPostBack) { tbEmail.Text = u.Email; if (artist != null) { tbName.Text = artist.Name; tbAddress.Text = artist.Address; tbContact.Text = artist.ContactNo; date = (DateTime)artist.DateOfBirth; } else { tbName.Text = customer.Name; tbAddress.Text = customer.Address; tbContact.Text = customer.ContactNo; date = (DateTime)customer.DateOfBirth; } ddlYear.SelectedValue = date.Year.ToString(); ddlMonth.SelectedValue = date.Month.ToString(); updateDay(); } }
//Update the item in the database public void UpdateItem(int updateCartID, int updateProductID, int quantity) { using (var _db = new GalleryEntities1()) { try { var myItem = (from c in _db.CARTITEMs where c.CartId == updateCartID && c.PRODUCT.ProductId == updateProductID select c).FirstOrDefault(); if (myItem != null) { myItem.Quantity = quantity; _db.SaveChanges(); } } catch (Exception exp) { throw new Exception("ERROR: Unable to Update Cart Item - " + exp.Message.ToString(), exp); } } }
public void FormViewPayment_InsertItem() { String orderid = (String)Session["orderid"]; int orderidInt = Convert.ToInt32(Session["orderid"]); TextBox address = (TextBox)FormViewPayment.FindControl("txtboxAddress"); Session["address"] = address.Text; using (var _db1 = new GalleryEntities1()) { try { var myItem = (from c in _db1.ORDERs where c.OrderId == orderidInt select c).FirstOrDefault(); if (myItem != null) { myItem.status = "Paid"; _db1.SaveChanges(); } } catch (Exception exp) { throw new Exception("ERROR: Unable to Update Order Status - " + exp.Message.ToString(), exp); } PAYMENT payment = new PAYMENT(); TryUpdateModel(payment); payment.Date = DateTime.Now; payment.OrderId = orderid; // Guid userId = (Guid)Membership.GetUser().ProviderUserKey; if (ModelState.IsValid) { GalleryEntities1 _db = new GalleryEntities1(); _db.PAYMENTs.Add(payment); _db.SaveChanges(); } Response.Redirect("~/PaymentSucess.aspx"); } }
//Remove the item from the database public void RemoveItem(int removeCartID, int removeProductID) { using (var _db = new GalleryEntities1()) { try { var myItem = (from c in _db.CARTITEMs where c.CartId == removeCartID && c.PRODUCT.ProductId == removeProductID select c).FirstOrDefault(); if (myItem != null) { // Remove Item. _db.CARTITEMs.Remove(myItem); _db.SaveChanges(); } } catch (Exception exp) { throw new Exception("ERROR: Unable to Remove Cart Item - " + exp.Message.ToString(), exp); } } }
// The id parameter name should match the DataKeyNames value set on the control public void fvAddItem_UpdateItem([QueryString] int ProductId) { Testing.Models.PRODUCT item = null; GalleryEntities1 _db = new GalleryEntities1(); item = _db.PRODUCTs.Find(ProductId); // Load the item here, e.g. item = MyDataLayer.Find(id); if (item == null) { // The item wasn't found ModelState.AddModelError("", String.Format("Item with id {0} was not found", ProductId)); return; } TryUpdateModel(item); //To convert the image to binary FileUpload imageUpload = (FileUpload)fvAddItem.FindControl("imageUpload"); HttpPostedFile postedFile = imageUpload.PostedFile; string fileName = Path.GetFileName(postedFile.FileName); string fileExtension = Path.GetExtension(fileName); int fileSize = postedFile.ContentLength; if (fileExtension.ToLower() == ".jpg" || fileExtension.ToLower() == ".bmp" || fileExtension.ToLower() == ".gif" || fileExtension.ToLower() == ".png") { Stream stream = postedFile.InputStream; BinaryReader binaryReader = new BinaryReader(stream); byte[] bytes = binaryReader.ReadBytes((int)stream.Length); item.Image = bytes; } if (ModelState.IsValid) { // Save changes here, e.g. MyDataLayer.SaveChanges(); _db.SaveChanges(); Response.Redirect("~/UpdateGallery.aspx"); } }
protected void btnPayment_Click(object sender, EventArgs e) { GalleryEntities1 _db = new GalleryEntities1(); ShoppingCart cs = new ShoppingCart(); List <CARTITEM> orderItem = cs.GetCartItems(); ORDER order = new ORDER { date = DateTime.Now, discount = 0, UserId = (Guid)u.ProviderUserKey, //PaymentId = null, status = "pending" }; _db.ORDERs.Add(order); _db.SaveChanges(); for (int i = 0; i < orderItem.Count(); i++) { ORDERDETAIL orderDetail = new ORDERDETAIL(); orderDetail.ProductId = orderItem[i].ProductId; orderDetail.OrderId = order.OrderId; orderDetail.Quantity = orderItem[i].Quantity; orderDetail.TotalPrice = (orderItem[i].Quantity * _db.PRODUCTs.Find(orderItem[i].ProductId).Price); _db.ORDERDETAILs.Add(orderDetail); _db.SaveChanges(); } Session["total"] = cs.GetTotal().ToString(); Session["orderid"] = order.OrderId.ToString(); Response.Redirect("~/Payment.aspx"); }
protected void Page_Load(object sender, EventArgs e) { if (HttpContext.Current.User != null && HttpContext.Current.User.Identity.IsAuthenticated) { MembershipUser u = Membership.GetUser(HttpContext.Current.User.Identity.Name); String name = u.UserName; Guid id = (Guid)u.ProviderUserKey; int cartId = 123; using (GalleryEntities1 db = new GalleryEntities1()) { cartId = (from c in db.CARTs where c.UserId == id select c.CartId).First(); } HttpContext.Current.Session["cartId"] = cartId; PanelLogin.Style.Add("display", "none"); btnLogin.Visible = false; btnRegister.Visible = false; btnLogout.Visible = true; } bool loginStatus = (System.Web.HttpContext.Current.User != null) && System.Web.HttpContext.Current.User.Identity.IsAuthenticated; if (loginStatus) { li_myaccount.Style["display"] = "block"; } else { li_myaccount.Style["display"] = "none"; li_myartwork.Style["display"] = "none"; } if (!Page.User.IsInRole("Artists")) { li_sales.Visible = false; li_myartwork.Visible = false; } }
public void fvAddItem_InsertItem() { var item = new PRODUCT(); TryUpdateModel(item); //Get the username for the currently logged in user Guid userId = (Guid)Membership.GetUser().ProviderUserKey; item.ArtistId = userId; //To convert the image to binary FileUpload imageUpload = (FileUpload)fvAddItem.FindControl("imageUpload"); HttpPostedFile postedFile = imageUpload.PostedFile; string fileName = Path.GetFileName(postedFile.FileName); string fileExtension = Path.GetExtension(fileName); int fileSize = postedFile.ContentLength; if (fileExtension.ToLower() == ".jpg" || fileExtension.ToLower() == ".bmp" || fileExtension.ToLower() == ".gif" || fileExtension.ToLower() == ".png") { Stream stream = postedFile.InputStream; byte[] bytes = ResizeUploadedImage(stream); item.Image = bytes; } item.Description = item.Description.Replace(Environment.NewLine, "<br />"); if (ModelState.IsValid) { // Save changes here GalleryEntities1 _db = new GalleryEntities1(); _db.PRODUCTs.Add(item); _db.SaveChanges(); Response.Redirect("~/ViewGallery.aspx"); } }
//Update the shopping cart database public void UpdateShoppingCartDatabase(int cartId, ShoppingCartUpdates[] CartItemUpdates) { using (var db = new GalleryEntities1()) { try { //get the number of updated items //Store them into a list int CartItemCount = CartItemUpdates.Count(); List <CARTITEM> myCart = GetCartItems(); foreach (var cartItem in myCart) { // Iterate through all rows within shopping cart list for (int i = 0; i < CartItemCount; i++) { if (cartItem.PRODUCT.ProductId == CartItemUpdates[i].ProductId) { //If the quantity is 0 or remove item checkbox is checked if (CartItemUpdates[i].PurchaseQuantity < 1 || CartItemUpdates[i].RemoveItem == true) { RemoveItem(cartId, cartItem.ProductId); } else { UpdateItem(cartId, cartItem.ProductId, CartItemUpdates[i].PurchaseQuantity); } } } } } catch (Exception exp) { throw new Exception("ERROR: Unable to Update Cart Database - " + exp.Message.ToString(), exp); } } }
public void fvAddProduct_InsertItem() { PRODUCT item = new PRODUCT(); TryUpdateModel(item); //Get the username for the currently logged in user MembershipUser membershipUser = Membership.GetUser("Username"); Guid userId = (Guid)membershipUser.ProviderUserKey; item.ArtistId = userId; Image productImage = (Image)fvAddProduct.FindControl("productImage"); byte[] imgData = System.IO.File.ReadAllBytes(Server.MapPath(productImage.ImageUrl)); item.Image = imgData; if (ModelState.IsValid) { // Save changes here GalleryEntities1 _db = new GalleryEntities1(); _db.PRODUCTs.Add(item); _db.SaveChanges(); Response.Redirect("~/ViewGallery.aspx"); } }
protected void Page_Load(object sender, EventArgs e) { using (ShoppingCart shoppingCart = new ShoppingCart()) { shoppingCart.EmptyCart(); } int orderid = Convert.ToInt32(Session["orderid"]); DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[4] { new DataColumn("ProductId", typeof(int)), new DataColumn("Name", typeof(string)), new DataColumn("Quantity", typeof(int)), new DataColumn("TotalPrice", typeof(Double)) }); GalleryEntities1 _db = new GalleryEntities1(); List <ORDERDETAIL> orderdetails = _db.ORDERDETAILs.Where( c => c.OrderId == orderid).ToList(); for (int i = 0; i < orderdetails.Count; i++) { PRODUCT product = _db.PRODUCTs.Find(orderdetails[i].ProductId); String stockCount = product.Stock; int stockCountValue = Convert.ToInt32(stockCount); stockCountValue--; stockCount = stockCountValue.ToString(); product.Stock = stockCount; _db.SaveChanges(); dt.Rows.Add(orderdetails[i].ProductId, product.Name, orderdetails[i].Quantity, orderdetails[i].TotalPrice); } GridView1.DataSource = dt; GridView1.DataBind(); double total1 = Convert.ToDouble(Session["total"]); // Label lblTotal = (Label)GridView1.FindControl("lblTotal"); lblTotal.Text = String.Format("{0:0.00}", total1); //for receipt email string companyName = "Gallery Website"; string address = Convert.ToString(Session["address"]); int orderid1 = Convert.ToInt32(Session["orderid"]); int orderNo = orderid1; DataTable dt1 = new DataTable(); dt1.Columns.AddRange(new DataColumn[4] { new DataColumn("ProductId", typeof(int)), new DataColumn("Name", typeof(string)), new DataColumn("Quantity", typeof(int)), new DataColumn("Total Price", typeof(Double)) }); GalleryEntities1 _db1 = new GalleryEntities1(); List <ORDERDETAIL> orderdetails1 = _db1.ORDERDETAILs.Where( c => c.OrderId == orderid1).ToList(); for (int i = 0; i < orderdetails1.Count; i++) { PRODUCT product = _db1.PRODUCTs.Find(orderdetails1[i].ProductId); dt1.Rows.Add(orderdetails1[i].ProductId, product.Name, orderdetails1[i].Quantity, orderdetails1[i].TotalPrice); } using (StringWriter sw = new StringWriter()) { using (HtmlTextWriter hw = new HtmlTextWriter(sw)) { StringBuilder sb = new StringBuilder(); //Generate Invoice/Receipt Header. sb.Append("<table width='100%' cellspacing='0' cellpadding='2'>"); sb.Append("<tr><td align='center' style='background-color: #18B5F0' colspan = '2'><b>Receipt</b></td></tr>"); sb.Append("<tr><td colspan = '2'></td></tr>"); sb.Append("<tr><td><b>Order No: </b>"); sb.Append(orderNo); sb.Append("</td><td align = 'right'><b>Date: </b>"); sb.Append(DateTime.Now); sb.Append(" </td></tr>"); sb.Append("<tr><td><b>Company Name: </b>"); sb.Append(companyName); sb.Append("</td><td align = 'right'><b>Address: </b>"); sb.Append(address); sb.Append("</td></tr>"); sb.Append("</table>"); sb.Append("<br />"); //Generate Invoice (Bill) Items Grid. sb.Append("<table border = '1'>"); sb.Append("<tr>"); foreach (DataColumn column in dt1.Columns) { sb.Append("<th>"); sb.Append(column.ColumnName); sb.Append("</th>"); } sb.Append("</tr>"); foreach (DataRow row in dt1.Rows) { sb.Append("<tr>"); foreach (DataColumn column in dt1.Columns) { sb.Append("<td>"); sb.Append(row[column]); sb.Append("</td>"); } sb.Append("</tr>"); } sb.Append("<tr><td align = 'right' colspan = '"); sb.Append(dt1.Columns.Count - 1); sb.Append("'>Total</td>"); sb.Append("<td>"); double total2 = Convert.ToDouble(Session["total"]); sb.Append(String.Format("{0:0.00}", total2)); sb.Append("</td>"); sb.Append("</tr></table>"); //Export HTML String as PDF. StringReader sr = new StringReader(sb.ToString()); Document pdfDoc1 = new Document(PageSize.A4, 10f, 10f, 10f, 0f); HTMLWorker htmlparser = new HTMLWorker(pdfDoc1); using (MemoryStream memoryStream = new MemoryStream()) { PdfWriter writer = PdfWriter.GetInstance(pdfDoc1, memoryStream); pdfDoc1.Open(); htmlparser.Parse(sr); pdfDoc1.Close(); byte[] bytes = memoryStream.ToArray(); memoryStream.Close(); MembershipUser u = Membership.GetUser(User.Identity.Name); _db = new Models.GalleryEntities1(); MailMessage mm = new MailMessage("*****@*****.**", u.Email); mm.Subject = "Receipt PDF"; mm.Body = "Receipt PDF Attachment"; mm.Attachments.Add(new Attachment(new MemoryStream(bytes), "ReceiptPDF.pdf")); mm.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.EnableSsl = true; System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential(); NetworkCred.UserName = "******"; NetworkCred.Password = "******"; smtp.UseDefaultCredentials = true; smtp.Credentials = NetworkCred; smtp.Port = 587; try { smtp.Send(mm); }catch (Exception ex) { Console.Write(ex.StackTrace); } } } } }
protected void GenerateInvoicePDF(object sender, EventArgs e) { string companyName = "Gallery Website"; string address = Convert.ToString(Session["address"]); int orderid = Convert.ToInt32(Session["orderid"]); int orderNo = orderid; DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[4] { new DataColumn("ProductId", typeof(int)), new DataColumn("Name", typeof(string)), new DataColumn("Quantity", typeof(int)), new DataColumn("Total Price", typeof(Double)) }); GalleryEntities1 _db = new GalleryEntities1(); List <ORDERDETAIL> orderdetails = _db.ORDERDETAILs.Where( c => c.OrderId == orderid).ToList(); for (int i = 0; i < orderdetails.Count; i++) { PRODUCT product = _db.PRODUCTs.Find(orderdetails[i].ProductId); dt.Rows.Add(orderdetails[i].ProductId, product.Name, orderdetails[i].Quantity, orderdetails[i].TotalPrice); } using (StringWriter sw = new StringWriter()) { using (HtmlTextWriter hw = new HtmlTextWriter(sw)) { StringBuilder sb = new StringBuilder(); //Generate Invoice (Bill) Header. sb.Append("<table width='100%' cellspacing='0' cellpadding='2'>"); sb.Append("<tr><td align='center' style='background-color: #18B5F0' colspan = '2'><b>Receipt</b></td></tr>"); sb.Append("<tr><td colspan = '2'></td></tr>"); sb.Append("<tr><td><b>Order No: </b>"); sb.Append(orderNo); sb.Append("</td><td align = 'right'><b>Date: </b>"); sb.Append(DateTime.Now); sb.Append(" </td></tr>"); sb.Append("<tr><td><b>Company Name: </b>"); sb.Append(companyName); sb.Append("</td><td align = 'right'><b>Address: </b>"); sb.Append(address); sb.Append("</td></tr>"); sb.Append("</table>"); sb.Append("<br />"); //Generate Invoice (Bill) Items Grid. sb.Append("<table border = '1'>"); sb.Append("<tr>"); foreach (DataColumn column in dt.Columns) { sb.Append("<th>"); sb.Append(column.ColumnName); sb.Append("</th>"); } sb.Append("</tr>"); foreach (DataRow row in dt.Rows) { sb.Append("<tr>"); foreach (DataColumn column in dt.Columns) { sb.Append("<td>"); sb.Append(row[column]); sb.Append("</td>"); } sb.Append("</tr>"); } sb.Append("<tr><td align = 'right' colspan = '"); sb.Append(dt.Columns.Count - 1); sb.Append("'>Total</td>"); sb.Append("<td>"); double total1 = Convert.ToDouble(Session["total"]); sb.Append(String.Format("{0:0.00}", total1)); sb.Append("</td>"); sb.Append("</tr></table>"); //Export HTML String as PDF. StringReader sr = new StringReader(sb.ToString()); Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f); HTMLWorker htmlparser = new HTMLWorker(pdfDoc); PdfWriter writer = PdfWriter.GetInstance(pdfDoc, Response.OutputStream); pdfDoc.Open(); htmlparser.Parse(sr); pdfDoc.Close(); Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment;filename=Invoice_" + orderNo + ".pdf"); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Write(pdfDoc); Response.End(); } } }