appending to rtf string problems

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mikemac76

    appending to rtf string problems

    I am trying to build a test harness to practice appending strings to an rtf
    string. I am doing this to simulate the string I'll be sending over the wire
    and receiving on the other end of an IM application. Below is the code I use
    to test.

    I receive this error everytime I try to send the string from one rtb to
    another:

    "File Format is not valid Line 28" Line 28 is where I set rtb2 to the value
    of the newly concatanated string----rtb2.Rtf =rtbBuild;



    private void button1_Click(o bject sender, EventArgs e)
    {
    try
    {


    String msgCode = "101;";
    String socketid = "2,";
    String rtbVals = rtb1.Rtf.ToStri ng();
    String rtbBuild = msgCode + socketid + rtbVals;
    rtb2.Rtf =rtbBuild;
    }
    catch (Exception excep)
    {
    MessageBox.Show (excep.ToString ());
    }

    }



    any ideas as to why I'm receivng this error? Thanks for any help!


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: appending to rtf string problems

    Mike,

    The reason this happens is because you are adding text to the rtf text
    and trying to reassign it ot the Rtf property. Rtf is like Xml in the sense
    that there are delimiters before and after the content, and you can't just
    add something wherever you want in the string that makes up the RTF text.

    What you need to do is strip away the message code and the socket id
    before you set the Rtf property on the rich text box.


    Hope this helps.

    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "mikemac76" <mikemac76@disc ussions.microso ft.com> wrote in message
    news:4849C7CF-21C3-4CDB-AA81-F34861B1D9A7@mi crosoft.com...[color=blue]
    >I am trying to build a test harness to practice appending strings to an rtf
    > string. I am doing this to simulate the string I'll be sending over the
    > wire
    > and receiving on the other end of an IM application. Below is the code I
    > use
    > to test.
    >
    > I receive this error everytime I try to send the string from one rtb to
    > another:
    >
    > "File Format is not valid Line 28" Line 28 is where I set rtb2 to the
    > value
    > of the newly concatanated string----rtb2.Rtf =rtbBuild;
    >
    >
    >
    > private void button1_Click(o bject sender, EventArgs e)
    > {
    > try
    > {
    >
    >
    > String msgCode = "101;";
    > String socketid = "2,";
    > String rtbVals = rtb1.Rtf.ToStri ng();
    > String rtbBuild = msgCode + socketid + rtbVals;
    > rtb2.Rtf =rtbBuild;
    > }
    > catch (Exception excep)
    > {
    > MessageBox.Show (excep.ToString ());
    > }
    >
    > }
    >
    >
    >
    > any ideas as to why I'm receivng this error? Thanks for any help!
    >
    >[/color]


    Comment

    Working...