Converting Forms Output results to text file, or PDF file RRS feed

  • Question

  • i want that what result is appears in text boxes of Form, program will ask for to converting your output into a text file, pdf file or word files.

    Sunday, November 15, 2015 8:07 AM


  • You can simply loop over all the textboxes and dump the output into a text file:

    using (StreamWriter sw = new StreamWriter(filename))
        foreach (Control c in this.Controls)
            if (c is TextBox)
                sw.WriteLine((TextBoc c).Text);

    Of course it will be a bit more complex if your textboxes are nested within other controls such as Panels; you will need to recurse into these containers if this is your case.

    Writing PDF or Word files will be more complex, since there is no built-in support for them in .Net. Once you have gathered from your textboxes the text that you want to write, you can use a third-party library (do a search, there are several of them) to write it into a PDF. A Word file can be written by means of OLE automation if you have Word installed in the same computer as your application, or you can use an external library such as the free Microsoft's OpenXml SDK. Beware that this is not easy, it has a steep learning curve.

    • Proposed as answer by DotNet Wang Friday, November 20, 2015 8:12 AM
    • Marked as answer by Kristin Xie Monday, November 23, 2015 1:44 AM
    Sunday, November 15, 2015 11:03 AM