This is a migrated thread and some comments may be shown as answers.
Editor Delete Bug\Problem?
1 Answer 13 Views
This is a migrated thread and some comments may be shown as answers.
Ruairi
Top achievements
Rank 1
Ruairi asked on 04 Jul 2016, 09:07 AM

I've been playing around with the Editor control which is a great control however it seems to have a major bug\problem. When I edit my file in the editor it dosnt deal well with deletes.

I've a 3 line html (Sample.html) file like below.

<p>1 First line here.</p><p>2 Second line here.</p><p>3 Third line here.</p>

In the Editor I delete the second line and save the content and I expect to see:

<p>1 First line here.</p><p>3 Third line here.</p>

However what the editor actually creates is this:

<p>1 First line here.</p><p>3 Third line here.</p>><p>3 Third line here.</p>

Note the repeat of the line 3 and the </p>>  

This is completely wrong! Am I doing something wrong?

 

The code for my view and my controller are as below:

View:

@using Mallon.Reporting.Artifacts
@using Mallon.Reporting.Extensions
@using DiamondFireWeb.Gui.Controllers
@using System.Collections.Generic
@using DiamondFireWeb.Gui.Extensions
@using TemplateEditorHelper
@using Kendo.Mvc.UI.Fluent
 
@model ModelEditorHtml
@{
  ViewBag.Title = "Editor Test ";
  bool hideLayout = Convert.ToBoolean(ViewData["HideLayout"]);
  if (hideLayout == null || hideLayout == false)
  {
    Layout = "~/Views/Shared/_Layout.cshtml";
  }
  string imagesUrl = Url.GetRootUrl("/Content/TemplateImages/{0}");
}
@using (Html.BeginForm())
{
  @Html.AntiForgeryToken()
 
  <div>
    @Html.HiddenFor(m => m.FilePath)
    @(Html.Kendo().EditorFor(m => m.Content)
            .Name("Content")
            .HtmlAttributes(new { style = "width: 100%;height:440px" })
            .Tools(t =>
              {
                t.Clear();
                t.Bold().Italic().Underline();
                t.JustifyLeft().JustifyCenter().JustifyRight().JustifyFull();
                t.InsertUnorderedList().InsertOrderedList();
                t.Outdent().Indent();
                t.InsertImage();
                t.TableEditing();
                t.Formatting();
                t.CleanFormatting();
                t.FontName();
                t.FontSize();
                t.FontColor().BackColor();
                t.Print();
              }
            )
            .Resizable(resizable => resizable.Content(true).Toolbar(true))
            //.ImageBrowser(imageBrowser => imageBrowser
            //  .Image(imagesUrl)
            //  .Read("Read", "ImageBrowser")
            //  .Upload("Upload", "ImageBrowser")
            //  .Thumbnail("Thumbnail", "ImageBrowser"))
)
    <input type="submit" class="k-button" />
  </div>
}

 

Controller Methods:

public ActionResult EditorTest()
{
  ModelEditorHtml m = new ModelEditorHtml();
  m.FilePath = @"C:\Data\Sample.html";
  m.Content = System.IO.File.ReadAllText(m.FilePath);
  return View(m);
}
 
[HttpPost]
[ActionName("EditorTest")]
public ActionResult EditorTestSave(ModelEditorHtml m)
{
  string htmlValue = HttpUtility.HtmlDecode(m.Content);
 
  using (FileStream file = new FileStream(m.FilePath, FileMode.Open, FileAccess.ReadWrite, FileShare.None))
  {
    using (StreamWriter writer = new StreamWriter(file, Encoding.UTF8))
    {
      writer.Write(htmlValue);
    }
  }
  return RedirectToAction("EditorTest");
}

 

Model:

public class ModelEditorHtml
{
  [AllowHtml]
  public string Content { get; set; }
 
  public string FilePath { get; set; }
}

 

 

 

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Ruairi
Top achievements
Rank 1
answered on 04 Jul 2016, 09:29 AM

Solved!

Apologies Telerik - the problem was in my code.

In my Controller save method I had:

using (FileStream file = new FileStream(template.File.AsLocalFile().Path, FileMode.Open, FileAccess.ReadWrite, FileShare.None))
    {
      using (StreamWriter writer = new StreamWriter(file, Encoding.UTF8))
      {
        writer.Write(htmlValue);
      }
    }

This was appending the content into the text file (wrongly I might add). The StreamWriter has a overload that 'Overwrites' the file content once I called this it worked correctly, like below:

using (StreamWriter writer = new StreamWriter(m.FilePath, false))
     {
       writer.Write(htmlValue);
     }

Asked by
Ruairi
Top achievements
Rank 1
Answers by
Ruairi
Top achievements
Rank 1
Share this question
or