How to export richtexteditor textbox values(images) to Ms word.. ?
kindly help......im trying to the below the sample code...im geting only text,,and images are not came...
aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CS.aspx.cs" ValidateRequest = "false" EnableEventValidation="false" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>TinyMCE ASP.Net Example</title>
<script type="text/javascript" src="tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
tinyMCE.init({
mode : "textareas",
theme : "advanced",
plugins : "safari,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,imagemanager,filemanager",
theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor, insertimage",
theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak,|,insertfile,insertimage",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : false,
template_external_list_url : "js/template_list.js",
external_link_list_url : "js/link_list.js",
external_image_list_url : "js/image_list.js",
media_external_list_url : "js/media_list.js",
height:300
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Panel ID = "pnlEditor" runat = "server" >
<asp:TextBox ID="RichTextBox" runat="server" TextMode = "MultiLine" ><br />
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="btnUpload_Click" />
<asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" Visible = "false" OnClick="btnCancel_Click" />
<asp:Label ID="lblDisplay" runat="server" Text="" Visible = "false" >
<asp:Button ID="btn" runat="server" OnClick="GenerateMsWordDoc" Text="Generate Ms Word Document" />
</div>
</form>
</body>
</html>
aspx.cs
public partial class _Default : System.Web.UI.Page
{
protected void btnSave_Click(object sender, EventArgs e)
{
lblDisplay.Visible = true;
pnlEditor.Visible = false;
lblDisplay.Text = RichTextBox.Text;
btnSave.Visible = false;
btnCancel.Visible = true;
}
protected void btnCancel_Click(object sender, EventArgs e)
{
lblDisplay.Visible = false;
pnlEditor.Visible = true;
lblDisplay.Text = "";
RichTextBox.Text = "";
btnSave.Visible = true;
btnCancel.Visible = false;
}
protected void btnUpload_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string FileName = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
string FilePath = "images/" + FileName;
FileUpload1.SaveAs(Server.MapPath(FilePath));
RichTextBox.Text += string.Format("<img src = '{0}' alt = '{1}' />", FilePath, FileName);
}
}
public override void VerifyRenderingInServerForm(Control control)
{
}
protected void GenerateMsWordDoc(object sender, EventArgs e)
{
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=Test.doc");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/msword";
StringWriter sw = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(sw);
lblDisplay.RenderControl(htmlWrite);
Response.Write(sw.ToString());
Response.End();
}
}