[SCRIPT]
function OnBeforeOpen(args) {
if (args.itemType == "File" && (/\.(docx)$/i).test(this._selectedFile)) {
var file = args.model.selectedFolder + args.model.selectedItems[0];
$.ajax({
url: '@Url.Action("Importing", "FileExplorer")',
type: "POST",
dataType: "json",
data: { FilePath: file },
success: function (data) {
var rte = $("#rteSample").ejRTE("instance");
rte.setHtml(data);
var dialogObj = $("#dialogAPI").ejDialog("instance");
dialogObj.option("title", args.model.selectedItems[0]);
dialogObj.open();
}
});
}
}
[Controller]
public object Importing(string FilePath)
{
string HtmlString = string.Empty;
string path = System.Web.HttpContext.Current.Server.MapPath(FilePath);
//var path = FilePath;
if (path != null)
{
using (var mStream = new MemoryStream())
{
new WordDocument(path).Save(mStream, FormatType.Html);
mStream.Position = 0;
HtmlString = new StreamReader(mStream).ReadToEnd();
};
HtmlString = ExtractBodyContent(HtmlString);
foreach (var item in DecodeKeys())
{
HtmlString = HtmlString.Replace(item.Key, item.Value);
}
}
else HttpContext.Response.Write("Select any file to upload.");
return Json(HtmlString);
} |