Entering the text in TinyMCE through C# - c#

I have embedded the TinyMCE in WebBrowser control and using it as a HTML WYSIWYG editor in my WPF app.
On the html page containing TinyMCE, I have:
function getContent() {
return tinyMCE.get('elm1').getContent();
}
I am calling this function on the WPF Button click as follows to obtain the content of TinyMCE in C#:
string editHtml = this.webBrowser1.InvokeScript("getContent").ToString();
However I want to set the content of the TinyMCE from the file before it loads, just to show text previously entered by the user, so that he/she can continue to modify the older content, instead writing the new content. How can I set the content of the TinyMCE through C#.
Thank you.

If you are saving the data in database then on edit, select the data from table, and assign the text to your text box..
txbItemText.Text = ListofItems[0].description;

Related

C# Windows Form displaying PDF file use Ppdfview4net (Display the first page only)

I am using Ppdfview4net to display PDF file, the issue that I have and not able to find a solution the Ppdfview4net display the first page only. However, when checking the PDF file it contains more than one page.
public void LoadDocument(Stream fileNameStream, DisplayMode displayMode)
{
ShowHideLoaderForm(true);
DisplayMode = displayMode;
SetDisplayMode();
pdfDocument.Load(fileNameStream);
BindAnnotations();
ShowHideLoaderForm(false);
}
The PageLayout set in the PDF file is SinglePage so PDFView4NET displays a single page. You can switch between pages by setting the PageNumber property.
You can display all pages and navigate between them using the scrollbar if you set the PageDisplayLayout property on the viewer to OneColumn.
Disclaimer: I work for the company that develops PDFView4NET.

Text doesn't display correctly when loaded from SQL DB

I use FreeTextBox for my webpage. And when I load the text again from Database to display on a Label, it doesn't display correctly( still contain HTML tag: ,...)
Take a look at my code below ( load the text from the DB)
Datatable db= excute .....;
string content = db.Rows[0]["CONTENT"].toString();
Label1.Text= content;
Just a basic codes , I really don't know where is the mistake.
Label1.Text ----> Demo freetextbox<div> just a simple demo</div><div>dnalksdfasdflklsd</div>
Label1.Text = HttpUtilities.HtmlDecode(content);
It decode the text, and the text will be displayed correctly.

Modifying rich content on home page programmatically

I am provisioning site collections programmatically in SP2010. The process is working fine but I need to be able to customize some text on the home page that is contained in rich text (not in a web part). Is there a way to grab that HTML code and modify it from code? For instance, embedded within the home page, I have a title and a paragraph of text. I'd like to customize the title based on one of the input values provided from the provisioning request. Is it possible to do this? Any suggestions would be appreciated!
You can access the content area as follows:
PublishingWeb pw = null;
//"web" is your SPWeb, didn't include using statement for your SPSite/SPWeb in this sample
if (PublishingWeb.IsPublishingWeb(web))
{
pw = PublishingWeb.GetPublishingWeb(web);
}
//todo: add some handling here for if web is not a publishingWeb
//assuming your home page is the default, if not - get the correct page here
SPFile defaultpage = pw.DefaultPage;
if (!(defaultpage.CheckOutType == SPFile.SPCheckOutType.None))
{
//programatically creating this stuff, so cancel any unexpected checkouts
defaultpage.UndoCheckOut();
}
defaultpage.CheckOut();
//Field you want to add HTML in (Alternatively, retreive existing data and modify the HTML)
defaultpage.ListItemAllFields["PublishingPageContent"] = "string of HTML";
defaultpage.ListItemAllFields.Update();
defaultpage.CheckIn("My Comment");

How to enter the text in textarea using mshtml

I am facing a problem I have to fill a TextArea programatically. I used the following code.
System.Windows.Forms.HtmlElement reviewText = myDoc.GetElementById("review-text");
reviewText.InnerText = Program.mainForm.richTextBox1.Text.Trim();
This works fine and it sets the text in TextArea control. The problem that I am facing is that this text appears light gary. When the user clicks over this text it disappears. It happens only on first click.
So I tried the following code to first click this box and then set the text.
reviewText.InvokeMember("click");
And then tried to set the text in the TextArea but got the same behaviour.
I dug into the source of the page and found some script associated with this TextArea.
Source of TextArea
<textarea onkeyup="javascript:yelp.ui.widget.countChars(this.form.comment,5000);" onkeydown="javascript:yelp.ui.widget.countChars(this.form.comment,5000);" name="comment" id="review-text" class="form400" rows="8" cols="40" style="height: 86px;"></textarea>
Script associated with TextArea
<script type="text/javascript">
var bizName = "Geary Club";
if ($('review-text'))
{
new yelp.ui.widget.DefaultValueTextField($('review-text'), 'Please write here');
}
Will somebody suggest to me how to insert the text into this TextArea control?
Is this an ASP.NET web app? If it is, the System.Windows.Forms.HtmlElement is a problem. What I think is going on is that you need to somehow disable the new yelp.ui.widget.DefaultValueTextField JavaScript code when you're pre-filling the TextArea. Are you able to use an ASP.NET TextBox control with the multi-line properties set? If so, I'd use that and change your top code to just set the .Text property of the Textbox control.
Either way, in the Javascript (if this is jQuery), I'd do this:
if ($('review-text') && $('review-text').val() != "")
{
new yelp.ui.widget.DefaultValueTextField($('review-text'), 'Please write here');
}
That way the default value is only set if there is no text.
I changed the HTML of text area.And remove the class="form400 default_valued_text_field" attribute from its html.
myDoc = this.webBrowser1.Document;
myDoc.GetElementById("review-text").OuterHtml = "<textarea id=\"review-text\" onkeyup=\"javascript:ui.widget.countChars(this.form.comment,5000);\" onkeydown=\"javascript:ui.widget.countChars(this.form.comment,5000);\" name=\"comment\" rows=\"8\" cols=\"40\" style=\"height: 86px;\"></textarea>";
After that i set the inner text of this element
myDoc.GetElementById("review-text").InnerText = "Testing";

Dynamically adding TinyMCE editor to textbox

I am adding textboxes dynamically to a div. Something likhe this
$('#xyz').click(function()
{
$(#myDiv).append('<textarea></textarea>');
});
Now I want to attach tinymce editor to these textareas, Can you help me in doing this?
Try this:
$('#xyz').click(function() {
var myTextarea = $("<textarea></textarea>");
myTextarea.attr("id", "mce-editor");
$("#myDiv").append(myTextarea);
// this inistalises the TinyMCE editor upon the element with the id in the last parameter.
tinyMCE.execCommand("mceAddControl", false, "mce-editor");
});
You could even attach the tinymce element to the div directly, because you don't need a textarea in order to edit and submit text using a tinymce editor instance. Tinymce will create an editable iframe in the dom in which the user is able to edit html content. OnSave the editors content gets written back to the html element the tinymce editor was created for (this can be a textarea, a div, a paragraph or another html elment).
tinyMCE.execCommand('mceAddControl', false, 'myDiv');

Categories