Telerik is a leading vendor of ASP.NET AJAX, ASP.NET MVC, Silverlight, WinForms and WPF controls and components, as well as .NET Reporting, .NET ORM , .NET CMS, Code Analysis, Mocking, Team Productivity and Automated Testing Tools. Building on its expertise in interface development and Microsoft technologies, Telerik helps customers build applications with unparalleled richness, responsiveness and interactivity. Telerik products help thousands of companies to be more productive and deliver reliable applications under budget and on time.
Version Q2 2011 released 07/12/2011
select

Editor / Save in External File

Test.html will be open in a new window
   
  
 
 
   

  • Save In External File

    You can save the RadEditor content in an external text or HTML file as well as load the content from an external file in the editor by following the instructions below:

    1. Create an HTML file (test.html) in the root of your web application
    2. Declare RadEditor and an Asp.NET button in your page:
      <telerik:radeditor runat="server" ID="RadEditor1" ></telerik:radeditor>
      <asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click" />
    3. To save the RadEditor content in the external HTML file when the Submit button is pressed, add the following code inside the button click eventhandler in the codebehind:
      C#
      protected string path = "test.html"; //specify the path to your file
      ...
      protected void Button1_Click1(object sender, EventArgs e)
      {
      //Open file for writing and write content
      using (StreamWriter externalFile = new StreamWriter(this.MapPath(path), false))
      {
      externalFile.Write(RadEditor1.Content)
      ;
      }
      }
      VB.NET:
      Protected path As String = "test.html"
      ...
      'specify the path to your file
      Protected Sub Button1_Click1(ByVal sender As Object, ByVal e As EventArgs)
      'Open file for writing and write content
      Using externalFile As New StreamWriter(Me.MapPath(path), False)
      externalFile.Write(RadEditor1.Content)
      End Using
      End Sub
    4. To load the external file content in the RadEditor, read the file content with the ReadFile function and assign the returned string to the Html property of RadEditor in the Page_Load event:
      C#
      protected void Page_Load(object sender, EventArgs e)
      {
      if (!Page.IsPostBack)
      {
      RadEditor1.Content
      = ReadFile(Server.MapPath(path));
      }
      }

      protected string ReadFile(string path)
      {
      if (!System.IO.File.Exists(path))
      {
      return string.Empty;
      }
      using (System.IO.StreamReader sr = new System.IO.StreamReader(path))
      {
      return sr.ReadToEnd();
      }
      }

      VB.NET
      Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
      If Not Page.IsPostBack Then
      RadEditor1.Content = ReadFile(Server.MapPath(path))
      End If
      End Sub

      Protected Function
      ReadFile(ByVal path As String) As String
      If Not
      System.IO.File.Exists(path) Then
      Return String
      .Empty
      End If
      Using sr As New System.IO.StreamReader(path)
      Return sr.ReadToEnd()
      End Using
      End Function

Source Code

C# VB.NET
Show code in new window Demo isolation steps
  • <%@ Page Theme="Default" Language="vb" Debug="true" AutoEventWireup="true" CodeFile="DefaultVB.aspx.vb" Inherits="Telerik.Web.Examples.Editor.SaveInExternalFile.DefaultVB" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <%@ Register TagPrefix="qsf" Namespace="Telerik.QuickStart" %>
    <%@ Register TagPrefix="qsf" TagName="Header" Src="~/Common/Header.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="HeadTag" Src="~/Common/HeadTag.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="Footer" Src="~/Common/Footer.ascx" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <qsf:headtag id="Headtag1" runat="server"/>
        
    </head>
    <body class="BODY">
        <form id="form1" runat="server">
                             
            <qsf:header id="Header1" runat="server" NavigationLanguage="VB"/>
         <telerik:RadScriptManager ID="ScriptManager1" runat="server" />
        
            <telerik:RadAjaxLoadingPanel runat="server" ID="RadAjaxLoadingPanel1" Skin="Default">
            </telerik:RadAjaxLoadingPanel>

            <telerik:RadAjaxPanel runat="server" ID="RadAjaxPanel1" LoadingPanelID="RadAjaxLoadingPanel1">
                  <qsf:InformationBox ID="InformationBox1" runat="server">
                        <asp:Button ID="Button1" CssClass="button" runat="server" Text="Save to File" OnClick="Button1_Click1" style="margin-right:10px;"/>Test.html will be open in a new window<br />
                  </qsf:InformationBox>
                  <telerik:RadWindow
                                Title = "Saved content"
                                NavigateUrl="test.html"
                                VisibleOnPageLoad="false"
                                ReloadOnShow="true"
                                Skin="Default"
                                runat="server"
                                Behaviors="Maximize,Close,Move"
                                ID="RadWindow1"
                                VisibleStatusbar="false"
                                Width="700px"
                                Modal="true"
                                Height="500px" />
            </telerik:RadAjaxPanel>
            
         <telerik:radeditor runat="server" Skin="Default" ID="RadEditor1" SkinID="DefaultSetOfTools" ></telerik:radeditor>
           
           
            <qsf:footer runat="server" id="Footer1"/>
        </form>
    </body>
    </html>

Get more than expected!

 
 

Take your time to truly experience the power of RadControls for ASP.NET AJAX with a free 60-day trial backed up by Telerik’s unlimited dedicated support.

Download your RadControls for ASP.NET AJAX trial and jumpstart your development with the available Getting Started resources.

If you have any questions, do not hesitate to contact us at sales@telerik.com.

Copyright 2002-2024 © Telerik. All right reserved
Telerik Inc, 201 Jones Rd, Waltham, MA 02451