本文介绍了我试图将gridview数据导出到asp.net中的pdf时发生错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 如果我点击按钮(btnConverttoPDF)  form 
itwill将创建包含表单内所有内容的pdf ..
it ' s工作正常本地..

但是当应用程序部署在服务器中然后
它'
引发错误.. as 跟随



无法建立连接,因为目标机器主动拒绝它127.0.0.15:55374

WebException:无法连接到删除服务器

并提及文件的路径,如
E:\ Main \ OnlineSite \OnlineBanking\ClosingBalance.aspx.cs





我在这里注意到的是127.0.0.15是我的IP和55374是我开发应用程序的portno



我发现了问题.. 

< asp:Image ID = Image1 ImageUrl = http:// localhost:55374 / img / bank_logo.png runat = server >

上述控件导致问题..
htmlparser.Parse(sr);

我可以知道如何解决它?





我尝试了什么:



protected void btnconvert_Click(object sender,EventArgs e)

{

using(StringWriter sw = new StringWriter())

{

使用(HtmlTextWriter hw = new HtmlTextWriter(sw))

{

//导出所有页面

grdLast10trans.AllowPaging = false;

//调用函数,这里我将数据添加到数据源并在网格中进行双击
BindGrid();

content.RenderControl(hw);

StringReader sr = new StringReader(sw.ToString());

文件pdfDoc =新文件( PageSize.A3,10f,10f,10f,10f);

HTMLWorker htmlparser = new HTMLWorker(pdfDoc);



PdfWriter.GetInstance( pdfDoc,Response.OutputStream);

pdfDoc.Open();

//pdfDoc.NewPage();

htmlparser.Parse(sr); //这里发生错误

pdfDoc.Close();

Response.ContentType =application / pdf;

Response.AddHeader( content-disposition,attachment; filename = GridViewExport.pdf);

Response.Cache.SetCacheability(HttpCacheability.NoCache);

Response.Write(pdfDoc);

HttpContext.Current.ApplicationInstance.CompleteRequest();

}

}

}

解决方案

if i onclick of a button(btnConverttoPDF) in some form 
itwill create pdf with all the content inside the form..
it's working fine locally..

But when the application is deployed in server then 
it's raising an error.. as follows



"No connection could be made because the target machine actively refused it 127.0.0.15:55374"

WebException: unable to connect to the remove server

and mentioning the path of the file like
E:\Main\OnlineSite\OnlineBanking\ClosingBalance.aspx.cs



What i noticed here is 127.0.0.15 is my IP and 55374 is my portno where i developed the app

I found the issue.. 

<asp:Image ID="Image1" ImageUrl="http://localhost:55374/img/bank_logo.png" runat="server">

the above control is causing an issue.. during 
htmlparser.Parse(sr);

May i know How can i resolve it?



What I have tried:

protected void btnconvert_Click(object sender, EventArgs e)
{
using (StringWriter sw = new StringWriter())
{
using (HtmlTextWriter hw = new HtmlTextWriter(sw))
{
//To Export all pages
grdLast10trans.AllowPaging = false;
//Calling a Function, here im adding the data to the Datasource and diplaying in Grid
BindGrid();
content.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A3, 10f, 10f, 10f, 10f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);

PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
//pdfDoc.NewPage();
htmlparser.Parse(sr); //Error Occurring here
pdfDoc.Close();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Write(pdfDoc);
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
}
}

解决方案


这篇关于我试图将gridview数据导出到asp.net中的pdf时发生错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 19:44