簡體   English   中英

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

[英]Pdf file is not updating in asp.net application

在我的asp.net應用程序中,我們使用ITextSharp.dll生成pdf。現在,我的問題是每次打開相同的pdf(不刷新),除非直到清除我的瀏覽器歷史記錄都一樣。 我正在使用Chrome瀏覽器。

這是我的代碼

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) {
    }
}

正如您所說的,它在Localhost中運行,但不在生產服務器中運行,在我看來,這很可能是URL/Path問題。

1.觀察代碼后,您formFile創建一個字符串Url變量,而無需使用現有的String formFile變量。

因為您應該提供valid path ,所以需要使用formFile而不是Url因為您已經使用Server.MapPath()創建了formFile

嘗試這個:

/*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