简体   繁体   English

PDF文件在ASP.NET应用程序中未更新

[英]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. 在我的asp.net应用程序中,我们使用ITextSharp.dll生成pdf。现在,我的问题是每次打开相同的pdf(不刷新),除非直到清除我的浏览器历史记录都一样。 I am using chrome browser. 我正在使用Chrome浏览器。

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. 正如您所说的,它在Localhost中运行,但不在生产服务器中运行,在我看来,这很可能是URL/Path问题。

1. after observing your code, you are creating one more string Url variable without using the existing String formFile variable. 1.观察代码后,您formFile创建一个字符串Url变量,而无需使用现有的String formFile变量。

as you should provide the valid path you need to use the formFile instead of Url as you have created formFile using Server.MapPath() 因为您应该提供valid path ,所以需要使用formFile而不是Url因为您已经使用Server.MapPath()创建了formFile

Try This: 尝试这个:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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