We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Reading "fields" written by TX text control to RTF file

I used this code to write an RTF file with TX Text Control (this is with their .NET version 12, but all recent versions are similar):

private void addText(String s)
    tx.Select(tx.Text.Length, 0);
    tx.Selection.Text = s;

private void addLine(String s)
    addText(s + "\n\r");

private void button1_Click(object sender, EventArgs e)
    tx.Selection.FontName = "Courier New";
    tx.Selection.Text = "hello world\n\r";

    tx.Select(tx.Text.Length, 0);
    tx.Selection.FontName = "Arial";
    tx.Selection.Text = "another line\n\r";

    tx.Select(tx.Text.Length, 0);

    TXTextControl.TextField f = new TXTextControl.TextField("text in text field");
    f.ID = 1;
    f.Name = "FirstFieldName";

    addLine("\n\rafter text field");

    TXTextControl.HypertextLink link = new TXTextControl.HypertextLink("hypertext link text", @"<http://www.yahoo.com>");
    link.ID = 2;
    link.Name = "HypertextFieldName";

    addLine("\n\rafter hypertext link");

    tx.Save(@"C:\temp\tx-fields-rtf.rtf", TXTextControl.StreamType.RichTextFormat);

That generates the attached file tx-fields-rtf.rtf.

If I load that file in Aspose and save to RTF with ‘new Document(@“c:\temp\tx-fields-rtf.rtf”, LoadFormat.Rtf, string.Empty);’ and ‘doc.Save(@“c:\temp\tx-fields-from-aspose.rtf”, SaveFormat.Rtf);’, it loses the field codes as in attached tx-fields-from-aspose.rtf. First question, is there any way to maintain those field codes?

Second question: in Document Explorer demo, the hyperlink field exists as a “field”, but the “text field” does not. Is there any way to pick up information about the “text field” in Aspose Words?

I understand I could use TX to read the files and generate the structure in Aspose Words programmatically, but wondering about an all-Aspose approach?


Thanks for your request. I cannot see any fields in your document except HYPERLINK. Just open your document in MS Word and press Alt+F9 to see fields in your document.
Best regards.

Hi Aleksey -

You’re right, the data I’m concerned about is not a FIELD when loaded into Word.

But while I’m not sure of the terminology, it is tagged in the RTF like this:

{\txfieldstart\txfieldtype0\txfieldflags128\txfielddataval1\txfielddata 460069007200730074004600690065006c0064004e0061006d0065000000}text in text field{\txfieldend}

Once the file is loaded into Aspose.words, is there any way to access that “txfielddata” hex text, and the fact that “text in text field” is enclosed between those *\txfieldstart and *\txfieldend markers?


Thanks for your request. There are no TX fields in RTF specification, that’s why Aspose.Words ignores them as well as MS Word. It seems to be the same question here:
Best regards.

Hi Alexey -

Yes, that’s a closely related question. As I understand the RTF spec, programs writing RTF are permitted to extend RTF in the way TX does, and programs reading it are permitted to “interpret” those extensions if they so desire.

I hadn’t previously tested how those fields would come over to Word. But since you point out that Word doesn’t recognize them, I can understand that Aspose wouldn’t either, since Aspose focus is much more on the Word file format than on RTF.

Thanks for your help.