This is a migrated thread and some comments may be shown as answers.

Save in file issue

3 Answers 114 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Patxi
Top achievements
Rank 1
Patxi asked on 21 Apr 2009, 03:04 PM
Hi,

I open an aspx page into the editor.  The user change its content and later I want to save it in the same file.

For so I have used a snippet code that I have found in ASP.NET for AJAX 2009 Q1.
        private bool _contentUpdated = false
        private string _editorContent = string.Empty; 
 
        private string EditorMatchEvaluator(Match m) 
        { 
            _contentUpdated = true
            string newContent = m.Groups[1].Value + _editorContent + "</content>"
            return newContent; 
        } 
 
        private void SaveInCurrentFile(RadEditor editor) 
        { 
            try 
            { 
                //read file 
                string physicalFileName = MapPathSecure(this.AppRelativeVirtualPath); 
                FileStream fs = new FileStream(physicalFileName, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite); 
                StreamReader sr = new StreamReader(fs); 
                string pageContent = sr.ReadToEnd(); 
 
                //update content 
                _contentUpdated = false
                _editorContent = editor.Content; 
                MatchEvaluator mEvaluator = new MatchEvaluator(EditorMatchEvaluator); 
                pageContent = Regex.Replace(pageContent, "(<(\\w+):RadEditor[^>]+?ID\\s*=\\s*['\"]?" + editor.ID + "['\"]?[^>]*>[\\s\\S]*?<content>)[\\s\\S]*?</content>", mEvaluator, RegexOptions.IgnoreCase | RegexOptions.Compiled); 
                //update file 
                if (_contentUpdated) 
                { 
                    fs.Seek(0, SeekOrigin.Begin); 
                    StreamWriter sw = new StreamWriter(fs); 
                    sw.BaseStream.SetLength(0); 
                    sw.Write(pageContent); 
                    sw.Flush(); 
                    sw.Close(); 
                } 
                else 
                { 
                    sr.Close(); 
                } 
            } 
            catch (Exception) 
            { 
                //"The File Encoding you have provided is not supported!" 
                //"Refresh the screen and try again!" 
                //"Another process or user is using the resource (ascx/aspx file) you are trying to update." 
                //"Check if the ASPNET user (IIS5) / NETWORK SERVICE account (IIS6) has write privileges for this file." 
            } 
        } 
    } 

I get an error in EditorMatchEvaluator function, with "Match" variable.
              Error    1    The type or namespace name 'Match' could not be found (are you missing a using directive or an assembly reference?)

I have added all references as possible but the problem still exist.

Do you know what am I missing?

Thank you in advance.


3 Answers, 1 is accepted

Sort by
0
Patxi
Top achievements
Rank 1
answered on 22 Apr 2009, 09:07 AM
Hello,

I have solved my problem. Finally I haven´t used this code, I have used "Save in external file" example code.

But now I´m getting another error. When I open an aspx page into editor, part of its content is open as comments. For example, take a look to this snippet code:
<%@ Page Title="" Language="C#" MasterPageFile="~/_Base/PlantillaWeb1.Master" AutoEventWireup="true" CodeBehind="fwePrincipal.aspx.cs" Inherits="WPlantillaWeb1.Principal" culture="auto" uiculture="auto" %> 

In the editor is shown as this:
<!--Page Title="" Language="C#" MasterPageFile="~/_Base/PlantillaWeb1.Master" AutoEventWireup="true" CodeBehind="fwePrincipal.aspx.cs" Inherits="WPlantillaWeb1.Principal" culture="auto" uiculture="auto"--> 

Why is it doing this?because when saving content in file and open it again, is showing as comment and application is not running.

I need your help. Does exist any way to solve this?

Thanks.

0
Accepted
Tervel
Telerik team
answered on 23 Apr 2009, 06:55 AM
Hi Patxi,

As I mentioned in my answer in your other related forum post here:
http://www.telerik.com/community/forums/aspnet-ajax/editor/charging-content-from-treeview.aspx
=====================================================================
However, the file is meant to be HTML file, and not ASPX file. Please note that ASPX server tags are parsed on the server by the ASP NET framework. Feeding this content to the editor, which will work with it on the client will not work well at all.
The editor is not a browser-based alternative of Visual Studio - and you seem to expect to use it in such a manner.
=====================================================================

In short, what you are experiencing now is the first of many problems that you will be facing if you continue with your approach of trying to edit ASPX files as if they were HTML files. This approach is not going to work as expected, and my suggestion is to re-consider it.

Best regards,
Tervel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Patxi
Top achievements
Rank 1
answered on 23 Apr 2009, 07:36 AM
Thank you Tervel,

I read what you wrote in the other post and I have taken it into account.  As I can show javscript code I thought ther would exit another way to show this code snippet.

I caught your idea, editor is only html editor and any other thing I want to edit it´s upt to me.

Thank you very much for your answer, again!
Tags
Editor
Asked by
Patxi
Top achievements
Rank 1
Answers by
Patxi
Top achievements
Rank 1
Tervel
Telerik team
Share this question
or