c# - Error as Input string was not in a correct format -


i getting following error on click of button input string not in correct format,

on click of button calling following method:

using system; using system.collections.generic; using system.linq; using system.web;  using system.io; using itextsharp.text.html.simpleparser; using itextsharp.text; using itextsharp.text.pdf; using itextsharp.text.html; /// <summary> /// summary description pdfgeneration /// </summary> public class pdfgeneration {     public pdfgeneration()     {         //         // todo: add constructor logic here         //     }      public void pdfgenerator(string name1, ajaxcontroltoolkit.htmleditor.editor editor1)     {          httpcontext.current.response.clear();         httpcontext.current.response.contenttype = "application/pdf";         // create pdf document         document pdfdocument = new document(pagesize.a4, 70, 55, 40, 25);          pdfwriter wri = pdfwriter.getinstance(pdfdocument, new filestream("e://" +name1 + ".pdf", filemode.create));          pdfwriter.getinstance(pdfdocument, httpcontext.current.response.outputstream);          pdfdocument.open();         string htmltext = editor1.content;         system.collections.generic.list<ielement> htmlarraylist = htmlworker.parsetolist(new stringreader(htmltext), null);          (int k = 0; k < htmlarraylist.count; k++)         {             pdfdocument.add((ielement)htmlarraylist[k]);         }          pdfdocument.close();         httpcontext.current.response.end();     }  } 

the stack trace is:

[formatexception: input string not in correct format.]    system.number.stringtonumber(string str, numberstyles options, numberbuffer& number, numberformatinfo info, boolean parsedecimal) +7471335    system.number.parsesingle(string value, numberstyles options, numberformatinfo numfmt) +115    system.single.parse(string s, numberstyles style, numberformatinfo info) +192    itextsharp.text.html.simpleparser.cellwrapper..ctor(string tag, chainedproperties chain) +148    itextsharp.text.html.simpleparser.htmltagprocessor_td.startelement(htmlworker worker, string tag, idictionary`2 attrs) +84    itextsharp.text.html.simpleparser.htmlworker.startelement(string tag, dictionary`2 attrs) +79    itextsharp.text.xml.simpleparser.simplexmlparser.processtag(boolean start) +30    itextsharp.text.xml.simpleparser.simplexmlparser.go(textreader reader) +1008    itextsharp.text.xml.simpleparser.simplexmlparser.parse(isimplexmldochandler doc, isimplexmldochandlercomment comment, textreader r, boolean html) +48    itextsharp.text.html.simpleparser.htmlworker.parsetolist(textreader reader, stylesheet style, idictionary`2 tags, dictionary`2 providers) +94    itextsharp.text.html.simpleparser.htmlworker.parsetolist(textreader reader, stylesheet style) +9    pdfgeneration.pdfgenerator(string name1, editor editor1) in c:\inetpub\wwwroot\dcis\app_code\pdfgeneration.cs:37    entryform.button4_click(object sender, eventargs e) in c:\inetpub\wwwroot\dcis\entryform.aspx.cs:224    system.web.ui.webcontrols.button.onclick(eventargs e) +111    system.web.ui.webcontrols.button.raisepostbackevent(string eventargument) +110    system.web.ui.webcontrols.button.system.web.ui.ipostbackeventhandler.raisepostbackevent(string eventargument) +10    system.web.ui.page.raisepostbackevent(ipostbackeventhandler sourcecontrol, string eventargument) +13    system.web.ui.page.raisepostbackevent(namevaluecollection postdata) +36    system.web.ui.page.processrequestmain(boolean includestagesbeforeasyncpoint, boolean includestagesafterasyncpoint) +1565 

how can resolve error?

@ geek error in code has posted

enter image description here

try this

public void createpdfdocument(string strhtml)     {          string strfilename = httpcontext.current.server.mappath("test.pdf");         // step 1: creation of document-object         document document = new document();         // step 2:         // create writer listens document         pdfwriter.getinstance(document, new filestream(strfilename, filemode.create));         stringreader se = new stringreader(strhtml);         htmlworker obj = new htmlworker(document);         document.open();         obj.parse(se);         document.close();         showpdf(strfilename);        }        public void showpdf(string strfilename)     {         response.clearcontent();         response.clearheaders();         response.addheader("content-disposition", "inline;filename=" + strfilename);         response.contenttype = "application/pdf";         response.writefile(strfilename);         response.flush();         response.clear();     } 

Comments