简体   繁体   中英

Pdf file is not updating in asp.net application

In my asp.net application we generating pdf using ITextSharp.dll Now my problem is every time same pdf is opening(not refreshing) unless until clear my browser history it is same. I am using chrome browser.

Here is my code

private void fillForm() {
    try {
        string Phone = "", Physical = "";
        string formFile = Server.MapPath("~\\Inspection.pdf");
        string newFile = Server.MapPath("~\\InspectionPrint.pdf");
        PdfReader reader = new PdfReader(formFile);
        PdfStamper stamper = new PdfStamper(reader, new FileStream(newFile, FileMode.Create));
        AcroFields fields = stamper.AcroFields;
        PdfContentByte d = new PdfContentByte(stamper.Writer);
        //getting values from DB
        SqlCommand comd = new SqlCommand("usp_PrintInspection", QMSConn);
        QMSConn.Open();
        comd.CommandType = CommandType.StoredProcedure;
        comd.Parameters.Add("@QuoteNumber", SqlDbType.VarChar);
        comd.Parameters["@QuoteNumber"].Value = Session["CurrQuoteNumber"].ToString();
        DataSet ds = new DataSet();
        SqlDataAdapter sqlAdapter = new SqlDataAdapter();
        sqlAdapter.SelectCommand = comd;
        sqlAdapter.Fill(ds, "Table");
        if (ds.Tables[0].Rows.Count > 0) {
            // set form fields
            string Name = ds.Tables[0].Rows[0]["NAME"].ToString();
            string Address1 = ds.Tables[0].Rows[0]["Address1"].ToString();
            string CompanyID = ds.Tables[0].Rows[0]["CompanyID"].ToString();
            string PolicyNumber = ds.Tables[0].Rows[0]["PolicyNumber"].ToString();

            fields.SetField("Name", Name);
            fields.SetField("Address1", Address1);
            fields.SetField("CompanyID ", CompanyID);
            fields.SetField("PolicyNumber", PolicyNumber);

            stamper.FormFlattening = false;
            stamper.Close();

            string file = "InspectionPrint";

            string Url = "../" + file + ".pdf";
            String js = @"WindowPopup('" + Url + "');";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Key", js, true);
        }
        else {
            showalert("No Record Available For This Quote");
        }
    }
    catch(exception ex) {
    }
}

as you are saying it is working in the Localhost but not in the production server, most likely it seems to me as an URL/Path issue.

1. after observing your code, you are creating one more string Url variable without using the existing String formFile variable.

as you should provide the valid path you need to use the formFile instead of Url as you have created formFile using Server.MapPath()

Try This:

/*string Url = "../" + file + ".pdf";*/ //comment or remove
String js = @"WindowPopup('" + formFile + "');";//use formFile instead of Url

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM