Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8569797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:25:12+00:00 2026-06-11T18:25:12+00:00

I have an aspx form in which user takes a survey and the survey

  • 0

I have an aspx form in which user takes a survey and the survey is saved to the database. After saving to the database, the survey responses given by the user are displayed so the user can save the response as pdf.

This is the function to save as pdf

//Save as PDF
protected void SaveAsPDF_Click(object sender, EventArgs e)
{
    Random nRandom = new Random(DateTime.Now.Second);
    string strFileName = nRandom.Next().ToString() + ".pdf";
    string target = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["NewResponsePDF"].ToString() + strFileName);

    string filepath = target;
    string filename = Path.GetFileName(filepath);

    Response.Clear();
    Response.ContentType = "application/pdf";
    Response.AddHeader("content-disposition", "attachment;filename=" + filename);

    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    StringWriter sw = new StringWriter();
    HtmlTextWriter hw = new HtmlTextWriter(sw);
    this.Page.Form.RenderControl(hw);
    StringReader sr = new StringReader(sw.ToString());
    Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
    HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
    PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
    pdfDoc.Open();
    htmlparser.Parse(sr);
    pdfDoc.Close();
    Response.Write(pdfDoc);
    Response.End();
}

It works fine and everything is well. The form has some text boxes. The user can enter text into the textbox. Sometimes, the user enters mathematical symbols like <, >, =. To make sure that the textbox value is saved to the database, the following ValidateRequest="false" has been done in the aspx file. But, the SaveAsPDF throws up an error as it is unable to parse these symbols.

I am pretty sure it is mostly these special symbols causing the issue with the

htmlparser.Parse(sr) method

because if there are no special symbols in the text boxes, PDF is generated fine.

Could you help me out on what I can do?/ Any pointers.

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T18:25:13+00:00Added an answer on June 11, 2026 at 6:25 pm

    You should first encode the input text by using HttpUtility.HtmlEncode before processing the text and performing the save.

    http://msdn.microsoft.com/en-us/library/73z22y6h.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a child page LoginContent.aspx which contains a login form. If the user
my structure is like this: master page aspx(web form) ascx(user control) I have a
I have aspx website in which I have multiple user controls. I want to
I have a field 'x' on the user control form which is included on
I have a aspx page which contains the following CheckBoxList. <form id=form1 runat=server> <asp:CheckBoxList
I am having a web form initially which have href as follows <a href=downloadInfo.aspx>ACH
I have to send an email which contains some checkboxes.My aspx form also have
I'm confused... I have a form on my aspx page which the text fields
I have a ASPX Page that contains several user controls, which are loaded dynamically
I have an ASP.NET web form on which I'm displaying a list of database

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.