Hi. i have used itextsharp.dll in my project to generate pdf in my web project, it is working fine on local host but when i uploaded it on the staging server it generates the error
System.Security .SecurityExcept ion: That assembly does not allow partially trusted callers. Attached is the screen shot of the error. and my code is as follows
please help me out where i am doing wrong, i have also added
in the assemblyinfo.cs file under the properties folder in my project.. please someone tell me what should i do its urjent
...
Addan
System.Security .SecurityExcept ion: That assembly does not allow partially trusted callers. Attached is the screen shot of the error. and my code is as follows
Code:
protected void btnClear_Click(object sender, EventArgs e)
{
for (int i = 0; i < gvInstallmentReceipt.Rows.Count; i++)
{
TextBox txtOrderID = (TextBox)gvInstallmentReceipt.Rows[i].FindControl("txtReceiptNo");
TextBox txtTotalPrice = (TextBox)gvInstallmentReceipt.Rows[i].FindControl("txtDate");
TextBox txtReceivedFrom = (TextBox)gvInstallmentReceipt.Rows[i].FindControl("txtReceivedFrom");
TextBox txtFatherName = (TextBox)gvInstallmentReceipt.Rows[i].FindControl("txtFatherName");
TextBox txtNIC = (TextBox)gvInstallmentReceipt.Rows[i].FindControl("txtNIC");
TextBox txtCurrency = (TextBox)gvInstallmentReceipt.Rows[i].FindControl("txtCurrency");
TextBox txtAmount = (TextBox)gvInstallmentReceipt.Rows[i].FindControl("txtAmount");
TextBox txtChequeNo = (TextBox)gvInstallmentReceipt.Rows[i].FindControl("txtChequeNo");
TextBox txtChequeDate = (TextBox)gvInstallmentReceipt.Rows[i].FindControl("txtChequeDate");
TextBox txtDrawnThrough = (TextBox)gvInstallmentReceipt.Rows[i].FindControl("txtDrawnThrough");
CheckBoxList cbListOnAccountOf = (CheckBoxList)gvInstallmentReceipt.Rows[i].FindControl("cbListOnAccountOf");
CheckBoxList cbListFor = (CheckBoxList)gvInstallmentReceipt.Rows[i].FindControl("cbListFor");
TextBox txtBlock = (TextBox)gvInstallmentReceipt.Rows[i].FindControl("txtBlock");
TextBox txtUnitNo = (TextBox)gvInstallmentReceipt.Rows[i].FindControl("txtUnitNo");
TextBox txtSizedAt = (TextBox)gvInstallmentReceipt.Rows[i].FindControl("txtSizedAt");
TextBox txtType = (TextBox)gvInstallmentReceipt.Rows[i].FindControl("txtType");
TextBox txtCoveredArea = (TextBox)gvInstallmentReceipt.Rows[i].FindControl("txtCoveredArea");
TextBox txtInstallmentNo = (TextBox)gvInstallmentReceipt.Rows[i].FindControl("txtInstallmentNo");
TextBox txtRemarks = (TextBox)gvInstallmentReceipt.Rows[i].FindControl("txtRemarks");
var document = new Document(PageSize.A4, 50, 50, 25, 25);
// Create a new PdfWriter object, specifying the output stream
var output = new MemoryStream();
var writer = PdfWriter.GetInstance(document, output);
// Open the Document for writing
var writer1 = PdfWriter.GetInstance
(document, new FileStream(Request.PhysicalApplicationPath
+ "MonthlyInstallmentReceipts\\InstallmentReceipt" + txtChequeNo.Text + ".pdf",
FileMode.Create));
Session["ReceiptNo"] = txtChequeNo.Text;
document.Open();
var titleFont = FontFactory.GetFont("Arial", 18, Font.BOLD);
var subTitleFont = FontFactory.GetFont("Arial", 8, Font.BOLD);
var boldTableFont = FontFactory.GetFont("Verdana", 8, Font.BOLD);
var endingMessageFont = FontFactory.GetFont("Arial", 10, Font.ITALIC);
var bodyFont = FontFactory.GetFont("Verdana", 8, Font.NORMAL);
var footerKGC = FontFactory.GetFont("Verdana", 7, Font.NORMAL, Color.BLUE);
var footerAddress = FontFactory.GetFont("Verdana", 7, Font.NORMAL);
document.Add(new Paragraph(" ACKNOWLEDGEMENT", titleFont));
document.Add(new Paragraph(" Monthly Installment Receipt for the month of " + DateTime.Now.ToString("MMM,yyyy"), subTitleFont));
var ReceiptTable = new PdfPTable(2);
#region ReceiptTable
ReceiptTable.HorizontalAlignment = 0;
ReceiptTable.SpacingBefore = 40;
ReceiptTable.SpacingAfter = 10;
ReceiptTable.DefaultCell.Border = 1;
ReceiptTable.SetWidths(new int[] { 90, 60 });
ReceiptTable.AddCell(new Phrase("Receipt No:", boldTableFont));
ReceiptTable.AddCell(new Phrase(txtOrderID.Text, bodyFont));
ReceiptTable.AddCell(new Phrase("Date:", boldTableFont));
ReceiptTable.AddCell(new Phrase(txtTotalPrice.Text, bodyFont));
ReceiptTable.AddCell(new Phrase("Recieved with gratitude from Mr./Mrs./Ms:", boldTableFont));
ReceiptTable.AddCell(new Phrase(txtReceivedFrom.Text, bodyFont));
ReceiptTable.AddCell(new Phrase("S/O-D/O-W/O:", boldTableFont));
ReceiptTable.AddCell(new Phrase(txtFatherName.Text, bodyFont));
ReceiptTable.AddCell(new Phrase("bearing CNIC/Passport No:", boldTableFont));
ReceiptTable.AddCell(new Phrase(txtNIC.Text, bodyFont));
ReceiptTable.AddCell(new Phrase("an Amount of:", boldTableFont));
ReceiptTable.AddCell(new Phrase(txtAmount.Text + " " + txtCurrency.Text + " Only", bodyFont));
ReceiptTable.AddCell(new Phrase("through Cash/Crossed/Cheque/Pay Order/Band Draft No:", boldTableFont));
ReceiptTable.AddCell(new Phrase(txtChequeNo.Text, bodyFont));
ReceiptTable.AddCell(new Phrase("Dated:", boldTableFont));
ReceiptTable.AddCell(new Phrase(txtChequeDate.Text, bodyFont));
ReceiptTable.AddCell(new Phrase("Drawn through:", boldTableFont));
ReceiptTable.AddCell(new Phrase(txtDrawnThrough.Text, bodyFont));
ReceiptTable.AddCell(new Phrase("On Account of", boldTableFont));
string OnAccOf = string.Empty;
if (cbListOnAccountOf.SelectedValue == "T")
{ OnAccOf = "Token"; }
else if (cbListOnAccountOf.SelectedValue == "D") { OnAccOf = "Down Payments"; }
else if (cbListOnAccountOf.SelectedValue == "I") { OnAccOf = "Installments"; }
ReceiptTable.AddCell(new Phrase(OnAccOf, bodyFont));
string ForProduct = string.Empty;
if (cbListFor.SelectedValue == "P") { ForProduct = "Plot"; } else { ForProduct = "Villa"; }
ReceiptTable.AddCell(new Phrase("For", boldTableFont));
ReceiptTable.AddCell(new Phrase(ForProduct, bodyFont));
ReceiptTable.AddCell(new Phrase("Block:", boldTableFont));
ReceiptTable.AddCell(new Phrase(txtBlock.Text, bodyFont));
ReceiptTable.AddCell(new Phrase("Unit No", boldTableFont));
ReceiptTable.AddCell(new Phrase(txtUnitNo.Text, bodyFont));
ReceiptTable.AddCell(new Phrase("Sized At", boldTableFont));
ReceiptTable.AddCell(new Phrase(txtSizedAt.Text, bodyFont));
ReceiptTable.AddCell(new Phrase("Type", boldTableFont));
ReceiptTable.AddCell(new Phrase(txtType.Text, bodyFont));
ReceiptTable.AddCell(new Phrase("Covered Area", boldTableFont));
ReceiptTable.AddCell(new Phrase(txtCoveredArea.Text, bodyFont));
ReceiptTable.AddCell(new Phrase("Installment No", boldTableFont));
ReceiptTable.AddCell(new Phrase(txtInstallmentNo.Text, bodyFont));
ReceiptTable.AddCell(new Phrase("Remarks", boldTableFont));
ReceiptTable.AddCell(new Phrase(txtRemarks.Text, bodyFont));
ReceiptTable.AddCell(new Phrase(System.Environment.NewLine + System.Environment.NewLine + System.Environment.NewLine + System.Environment.NewLine + @"For Karachi Golf City (Pvt.) Ltd.
This reciept is subject to realization of payment transfer.
* Put a Tick in the applicable field and a Cross in the fields that are not applicable.", footerKGC));
ReceiptTable.AddCell(new Phrase(System.Environment.NewLine + System.Environment.NewLine + System.Environment.NewLine + System.Environment.NewLine + @"3rd Fl., Maqbool Complex, Plot 6, Block 7&8, J.C.H.S., Sharah-e-Faisal, Karachi, Pakistan
Tel. +92-21-32361271-2 Fax. +92-21-32361273 Email.", footerAddress));
#endregion
document.Add(ReceiptTable);
var logo = iTextSharp.text.Image.GetInstance(Server.MapPath("~/Images/logo.png"));
logo.SetAbsolutePosition(20, 740);
document.Add(logo);
document.Close();
//Response.ContentType = "application/pdf";
//Response.AddHeader("Content-Disposition", string.Format("attachment;filename=Receipt-{0}.pdf", txtInstallmentNo.Text));
//Response.BinaryWrite(output.ToArray());
SendEmail();
customer.UpdatePaymentStatus(Convert.ToInt32(Session["PaymentID"]));
Page.ClientScript.RegisterClientScriptBlock(typeof(string), "", "ShowSuccess()", true);
}
}
Code:
[assembly: AllowPartiallyTrustedCallers]
...
Addan