I'm using ASP.NET 2.0, with the pages posting back to themselves. I use code behind pages and I program in VB.
The page that uses the control is called with a querystring that contains the name of a text file. The control opens displaying the contents of that text file. I have no problem with that part, but I don't know how to save the changes back to the text file.
I don't know c# and can't decipher the sample pages. Can someone walk me through how to save the changes made in the editor? If you have a link to some VB samples it would be appreciated, or maybe an article or tutorial? I looked through the docs, but I couldn't find anything that made any sense to me.
Diane
The page that uses the control is called with a querystring that contains the name of a text file. The control opens displaying the contents of that text file. I have no problem with that part, but I don't know how to save the changes back to the text file.
I don't know c# and can't decipher the sample pages. Can someone walk me through how to save the changes made in the editor? If you have a link to some VB samples it would be appreciated, or maybe an article or tutorial? I looked through the docs, but I couldn't find anything that made any sense to me.
Diane
RE: Confused Newbie - how to save?
Diane
RE: Confused Newbie - how to save?
I'm not a .net person, but I'm using fck with classic ASP in 10s of project as part of a CMS:
user loads a file to editor / edit text / save bck to server.
To load & Save I'm using CreateObject("Scripting.FileSystemObject") - Google for it to get more details about this object, how you can write/read/delete/copy files.
Here are 2 functions that might help you
Function ReadPage(MyPath)
'MyPath is aboslute path to the file (/directory1/subdirectory1/file.htm)'
Set fso = CreateObject("Scripting.FileSystemObject")
dim objFileContents, strFileContents
set objFileContents = fso.OpenTextFile(server.mappath(MyPath), 1)
If objFileContents.AtEndOfStream Then
'Response.Write "file is empty"
else
strFileContents = objFileContents.ReadAll
end if
ReadPage = strFileContents
Set objFileContents = Nothing
Set strFileContents = Nothing
Set fso = Nothing
end Function
Function Write_Page(FileName, MyPath, Content)
'MyPath is the absoloute path to file
'Filename is ... well
'Content the value returns by FCKeditor
dim fso, folderObject, textStreamObject
Set fso = CreateObject("Scripting.FileSystemObject")
Set folderObject = fso.GetFolder(Server.Mappath(MyPath))
Set textStreamObject = folderObject.CreateTextFile(FileName,true,false)
textStreamObject.Write(ThisContent)
textStreamObject.Close ' remember to close it so that it writes the file
Set textStreamObject = Nothing
Set folderObject = Nothing
Set fso = Nothing
'response.Write content
end Function
My .net colleagues are telling me you can use fso in a similar way.
I hope this help.
Remi
RE: Confused Newbie - how to save?
I'm, not sure I understand what you're saying, but in trying to figure it out I found my problem. I have the editor code in the page load sub. Every time I clicked on any button, the page reloaded - resetting the contents of the editor. Sigh. I'm new to .NET and I'm still getting used to some things. I put the code that assigns the value of the editor contents to within a If Page.IsPostBack = False block. That fixed it.
I still don't think I have it quite right though. The source file starts with a line with one font, has a couple of empty lines, and continues with the default font. I added the word 'test' in one of the blank lines. It displayed in the same font as the first line. I clicked my save button (not the save button in the editor) and it saved fine, except it added a new empty line below 'test'. I clicked the button again and the top two lines disappeared. They had gone to the bottom of the page and were in the default font. I tried this again, clicking the save button on the editor itself and got the same result.
So what is you think I'm not saving? The source file or the editor contents? If it's the editor, it's possible I'm not saving it. I could be missing one or more steps. What do you do besides read text from a source, open the editor, ans write the text back to the destination?
Diane
RE: Confused Newbie - how to save?
Make sure you're not instering a carriage retuen by error before readin the content
Check also your css and make sure there are no weird 'float' or 'a P align' there
Remi
RE: Confused Newbie - how to save?
Well, that's not exactly true either. I can get the content of the editor - but I get the original content, not any of the changes that have been made.
The following causes the editor to successfully open with the contents of the file. sSource is a string containing the path and filename. This part works fine.
'Open a file for reading, grab the text
Dim Reader As New IO.StreamReader(File.Open(sSource, FileMode.Open))
Dim sText As String = Reader.ReadToEnd()
Reader.Close()
FCKeditor1.Value = sText
The editor fires up, I can see the file contents, I can make all kinds of changes. The editor works beautifully. But I can't save any of the changes. The following is an attempt to save the content of the editor after changes have been made.
Dim Writer As New IO.StreamWriter(File.Open(sSource, FileMode.Open))
Writer.Write(FCKeditor1.Value)
Writer.Close()
The value of FDKeditor1.value at this point is the original contents of the source file. This has been verified by inspecting the it's value while debugging.
Also, while editing, clicking on the save icon in the editor restores the editor contents back to the original, losing any changes.
I have to be doing something wrong here, but I can't figure out what it is.
Diane
RE: Confused Newbie - how to save?
I would be delighted to help, but I'm not a .net person, not even talking about C#.
That's true that the lack of documentation is frustrating.
when you're saying "The value of FDKeditor1.value at this point is the original contents", you mean the content unchanged, don't you.
Again I don't know enough about the language you're using (i don't want to mislead you), but the line
Dim Writer As New IO.StreamWriter(File.Open(sSource, FileMode.Open)) looks suspicious.
Would it be possible that you're reading the content of the file and not applying the changes before saving it.
A .net colleague who had a quick look at your code tends to confirm this, you shouldn't open your file before saving it..
Sorry i'm not much help
Remi
RE: Confused Newbie - how to save?
The ASP.NET wrapper component has a property other than ".value" for returning the results. I think it's ".HTML" or ".XHTML"... something like that (sorry, I don't have the project handy where I used it).
If you are dynamically adding the control in your page's code-behind file, be sure to do it during the "Page_Init" event. Also, only load the text file contents during "Page_Load" if Page.IsPostback is false.
Hope that helps.
-- T
RE: Confused Newbie - how to save?
Ok. I just logged into my development server at the other office and checked my source. It appears I was mistake about the property. ".Value" is the correct property to call. My reference I was thinking of was ".EnableXHTML". That is what I get for relying on my memory.
Sorry for the mis-information.
RE: Confused Newbie - how to save?
function FCKeditor_OnComplete( editorInstance )
{
window.status = editorInstance.Description ;
}
I don't need this? I'm not missing anything?
Diane
RE: Confused Newbie - how to save?
That line just takes some text (the editor.Description) and plops it down in the browser status bar. That shouldn't be a requirement to get FCKEditor to work. (Also note that due to recent browser anti-phishing security changes in FF and IE7, this no longer works anyway).
-- Tim
Re: Confused Newbie - how to save?
Sure you can use something like:
if (Page.IsPostBack)
{
FCKeditor editor = (FCKeditor)FormView1.FindControl("FCKeditor1");
string s = HttpUtility.HtmlEncode(editor.Value);
BusinessLogicLayer.updateDBContents(s, Request.QueryString["page"]);
}
else
{
FCKeditor fckeditor = new FCKeditor();
fckeditor.ID = "FCKeditor1";
fckeditor.Value = BusinessLogicLayer.getDBContents(Request.QueryString["page"]);
MainContentArea.Controls.Add(fckeditor); //MainContentArea is a div tag, or could be another control
}
What I'm having trouble with is the Page.IsPostBack will ALWAYS update the database page on postbacks, even if it wasn't caused by FCKeditor. So what extra condition can I put in 'if (Page.IsPostBack && ???)' to make sure that it was FCKeditor SAVE BUTTON who fired the postback? It has been pretty frustrating. Hope someone can help.
Re: Confused Newbie - how to save?
Re: Confused Newbie - how to save?
I use a hidden field TextBox1 to track the previous value in the editor. If what is in the editor differs from what is in my hidden field i will save that value.
If (Page.IsPostBack) Then
If (TextBox1.Text = fckTest.Value) Or (fckTest.Value.Trim = "") Then
Dim c As String = "" 'Same text
Else
Dim d As String = "" 'Changed text
TextBox1.Text = fckTest.Value
End If
End If