LoadRTF can't work when retrieve RTF data from database.

Last post 09-11-2009, 7:14 PM by hery2002. 7 replies.
Sort Posts: Previous Next
  •  09-10-2009, 2:33 AM 55510

    LoadRTF can't work when retrieve RTF data from database.

    code snippet
    ------------------------------------
            SqlConnection cnn = new SqlConnection(" Data Source=servername;Initial Catalog=database;Persist Security Info=True;");
            SqlCommand cmd = new SqlCommand(" SELECT [COLUMN] FROM [TABLE] WHERE [ID]=@pID ", cnn);
            cmd.Parameters.Add(new SqlParameter("@pID", SqlDbType.Int));
            cmd.Parameters["@pID"].Value = 1;
            SqlDataAdapter sda = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            using (cnn)
            {
                cnn.Open();
                sda.Fill(ds);
                if (null != ds) Editor1.LoadRTF(ds.Tables[0].Rows[0]["COLUMN"].ToString());
                cnn.Close();
            }
    -----------------------------
    And in this line *Editor1.LoadRTF(ds.Tables[0].Rows[0]["COLUMN"].ToString());*,it threw an error *can't find a part of the path *XXXX** something like this.
    I have go though the whole forums, but can't find any help.
    I'm not sure which did i miss? pls help.
    thanks.
    Filed under:
  •  09-10-2009, 4:23 AM 55518 in reply to 55510

    Re: LoadRTF can't work when retrieve RTF data from database.

    Hi hery2002,
     
    please make sure "ds.Tables[0].Rows[0]["COLUMN"].ToString()" return a correct path.
     
    Try to output the paht Response.Write(ds.Tables[0].Rows[0]["COLUMN"].ToString()) and make sure this file exist.
     
    Regards,
     
    Ken
  •  09-10-2009, 9:58 PM 55550 in reply to 55518

    Re: LoadRTF can't work when retrieve RTF data from database.

    Hi,Keneth:
     
         Thanks for your quick reply.
          I stored the content directly into our DB and then retrieve this content back to cuteeditor.
          I referred to the developer guide and I knew that the cuteeditor can load RTF content with the same format.
          just like this scenario:
          1) Save the Cuteeditor data as RTF.
            code snippet like this:
            -------------------------------------------------------------
            CuteEditor.Convertor.RTF.HTML2RTF html2rtf = new CuteEditor.Convertor.RTF.HTML2RTF(Editor1.Text);
            SqlConnection cnn = new SqlConnection(" Data Source=servername;Initial Catalog=database;Persist Security Info=True;");
            SqlCommand cmd = new SqlCommand(" UPDATE [TABLE] SET  [COLUMN]=@pCOLUMN WHERE ID=@pID ", cnn);
            cmd.Parameters.Add(new SqlParameter("@ppCOLUMN", SqlDbType.VarChar, 2000));
            cmd.Parameters["@pCOLUMN"].Value = html2rtf.RTF;
            cmd.Parameters.Add(new SqlParameter("@pID", SqlDbType.Int));
            cmd.Parameters["@pID"].Value = 1;
            using (cnn)
            {
                cnn.Open();
                cmd.ExecuteNonQuery();
                cnn.Close();
            }
    ----------------------------------------------------------------------
       2) And then I retrieve the data and convert to HTML.
           -------------------------------------------------
           SqlConnection cnn = new SqlConnection(" Data Source=servername;Initial Catalog=database;Persist Security Info=True;");
            SqlCommand cmd = new SqlCommand(" SELECT [COLUMN] FROM [TABLE] WHERE [ID]=@pID ", cnn);
            cmd.Parameters.Add(new SqlParameter("@pID", SqlDbType.Int));
            cmd.Parameters["@pID"].Value = 1;
            SqlDataAdapter sda = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            using (cnn)
            {
                cnn.Open();
                sda.Fill(ds);
                if (null != ds) Editor2.LoadRTF(ds.Tables[0].Rows[0]["COLUMN"].ToString());
                cnn.Close();
            }
           -------------------------------------------------
           Because another software just can read RTF format data,so we have no choice but store as RTF.
     
          When I debug those code, I found that the LoadRTF function will add the current path before my RTF data automatically.
          That means if my page run under http: localost:1234\CuteSoft\CuteEditor,
    and I suppose my content is "{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}} {\*\generator Msftedit 5.41.15.1507;}\viewkind4\uc1\pard\f0\fs20 Hello\par } ";
    And the LoadRTF will get this string http: localost:1234\CuteSoft\CuteEditor\{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}} {\*\generator Msftedit 5.41.15.1507;}\viewkind4\uc1\pard\f0\fs20 Hello\par } .
    That's the point.
    so I'm not sure if cuteeditor can support this scenario.
    Thanks for your regards.
    hery2002
  •  09-10-2009, 10:52 PM 55552 in reply to 55550

    Re: LoadRTF can't work when retrieve RTF data from database.

    Hi hery2002,
     
    LoadRTF methods need to provide the path of the file which you want to load(file not content).
     
    Please change to
     
     if (null != ds) Editor2.Text=ds.Tables[0].Rows[0]["COLUMN"].ToString();
     
    -------------------------------------------------
    Editor.LoadRTF Method 
     
    Loads the contents of a RTF file into the CuteEditor control.
     
    [Visual Basic]
    Public Sub LoadRTF( _
       ByVal _filename As String _
    )
    [C#]
    public void LoadRTF(
       string _filename
    );

    Parameters

    _filename The text file to load into CuteEditor

    Example

     
        editor1.LoadRTF("{\rtf1\........");
        
        editor1.LoadRTF("~/doc/mtRTF.RTF");
    
    Regards,
     
    Ken
  •  09-10-2009, 11:25 PM 55554 in reply to 55552

    Re: LoadRTF can't work when retrieve RTF data from database.

    Hi,Kennth:
          I agree with you.
          but how can we explain this example as you mentioned above?
          --------------------------
          editor1.LoadRTF("{\rtf1\........");
          --------------------------
          The parameter is the content of an RTF.
          And also in the  developer guide, there is a same example in the *RTF to HTML, HTML to RTF*section.
          -------------------------
    1. RTF to HTML
    In order to convert RTF to HTML, you would use LoadRTF Method: 
    LoadRTF Method
    Loads the contents of an RTF into the CuteEditor control
    // Load RTF string
    string t = @"{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}} {\*\generator Msftedit 5.41.15.1507;}\viewkind4\uc1\pard\f0\fs20 Hello\par } ";
    Editor1.LoadRTF(t);

    // Load RTF file
    Editor1.LoadRTF("document.rtf");
    -----------------------------------
    so if the LoadRTF function just support file path parameter, this example does NOT make sense. :)
    Thanks again.
    hery2002
     
  •  09-10-2009, 11:29 PM 55555 in reply to 55554

    Re: LoadRTF can't work when retrieve RTF data from database.

    So if we want to pass a RTF string paramter, how can we complish this task?
    Or if we store a RTF string into database ,and then how can we retieve this RTF as a readable format via CuteEditor?
    hery2002
  •  09-11-2009, 1:53 AM 55556 in reply to 55555

    Re: LoadRTF can't work when retrieve RTF data from database.

    Hi hery2002,
     
    You need to save your data as a rtf file and then use method LoadRTF() to load this file into editor.
     
    Regards,
     
    Ken
  •  09-11-2009, 7:14 PM 55574 in reply to 55556

    Re: LoadRTF can't work when retrieve RTF data from database.

    Hi,Kennth:
         Anyway,Thanks for your regards.
         As I mentioned, I must store the RTF content for certain purpose. 
         Fortunately,I found another solution to solove this problem.
    B/R
    Hery2002
View as RSS news feed in XML