How to insert/save string RTF - Aspxrichedit

Asked

Viewed 269 times

1

In my application, I search the database for a string that contains RTF and need to load it into Aspxrichedit. And when necessary, save Aspxrichedit content to an RTF string to store in the database. How can I do this in C#?

I managed indirectly by creating files to open/save, but it is impracticable because of performance. IE, the form below is unviable.

aspx.Cs file

protected void Page_Load(object sender, EventArgs e)
{
    string rtf = BuscaTexto();
    string open = @"Projects/PCMSO/PCMSO/App_Data/WorkDirectory/open" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".rtf";
    StreamWriter writer = new StreamWriter(open);
    writer.WriteLine(rtf);
    writer.Close();
    ASPxRichEdit1.Open(open);

    Delete(open);
}

public string Save()
{
    string salvo = @"Projects/PCMSO/PCMSO/App_Data/WorkDirectory/save" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt";
    ASPxRichEdit1.SaveCopy(salvo);
    string rtf_string = System.IO.File.ReadAllText(salvo);

    Delete(salvo);

    return rtf_string;
}

aspx file.

<td>                                                                            
   <form runat="server">
      <dx:ASPxRichEdit ID="ASPxRichEdit1" style="width: 100%; height: 400px" runat="server" WorkDirectory="~\App_Data\WorkDirectory"></dx:ASPxRichEdit>
   </form>
</td>
  • Include your Mac Up

  • And its surroundings

  • @lucaswmloin, did you read the documentation of the component that I passed to you in the other question? https://documentation.devexpress.com/AspNet/119372/ASP-NET-WebForms-Controls/Rich-Text-Editor/Examples/How-to-Insert-RTF-text-a-document

  • Yeah, but it’s not working.

  • Then include in your question the error presented.

1 answer

1


I got insert the string RTF in the document, as follows:

aspx.Cs file

protected void ASPxRichEdit1_Callback(object sender, DevExpress.Web.CallbackEventArgsBase e)
{
   string rtf = BuscaTexto();

   MemoryStream memoryStream = new MemoryStream();
   ASPxRichEdit1.SaveCopy(memoryStream, DocumentFormat.Rtf);
   memoryStream.Position = 0;

   var server = new RichEditDocumentServer();
   server.LoadDocument(memoryStream, DocumentFormat.Rtf);
   var pos = server.Document.CreatePosition(Convert.ToInt32(e.Parameter));
   server.Document.InsertRtfText(pos, rtf);

   memoryStream = new MemoryStream();
   server.SaveDocument(memoryStream, DocumentFormat.Rtf);
   ASPxRichEdit1.Open(Guid.NewGuid().ToString(), DocumentFormat.Rtf, () =>
   {
       return memoryStream.ToArray();
   });
}

aspx file.

<script>
    var startPosition = -1;
    function OnClick(s, e) {
        startPosition = rich.selection.intervals[0].start;
        rich.PerformCallback(startPosition);
    }
</script>

<td>
   <form runat="server">
        <dx:ASPxRichEdit ID="ASPxRichEdit1" ClientInstanceName="rich" style="width: 100%; height: 600px" runat="server" WorkDirectory="~\App_Data\WorkDirectory" OnCallback="ASPxRichEdit1_Callback"></dx:ASPxRichEdit>
   </form>
</td>

I got salvage rtf content in a string, as follows:

aspx file.

string t1 = Encoding.UTF8.GetString(ASPxRichEdit1.SaveCopy(DocumentFormat.Rtf));

Browser other questions tagged

You are not signed in. Login or sign up in order to post.