|
public IDictionary<string, string> DecodeKeys()
{
IDictionary<string, string> KeyValuePair = new Dictionary<string, string>()
{
{"\"", "'"},{"\r", " "},{"\n", " "},{"\r\n", " "},{"( )+", " "},{" ", " "},{"•", "*"},{"‹", "<"},
{"›", ">"},{"™", "(tm)"},{"©", "(c)"},{"®", "(r)"}
};
return KeyValuePair;
} |
|
[Script]
var file,sourcePath;
function OnBeforeOpen(args) {
var viewer = $("#dialogAPI").data("ejDialog");
if (args.itemType == "File" && (/\.(docx)$/i).test(this._selectedFile)) {
//you can get parent path using "args.model.selectedFolder"
//you can get selected file name using "args.model.selectedItems"
var file = args.model.selectedFolder + args.model.selectedItems[0];
if (viewer.isOpen()) {
alert("Already you are viewing another file");
args.cancel = true;
return;
}
//sending request to controller method to process pdf file and maintain count
$.get("/FileExplorer/GetFile", { path: file })
.done(function (data) {
//Check if the PDF file is already opened
if (data.openedCount < 1) {
sourcePath = data.path;
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();
}
});
}
else {
alert("Already (" + data.path + ") file is viewing by other user");
}
});
args.cancel = true;
}
}
function onDialogClose(args) {
$.get("/FileExplorer/CloseFile", { path: sourcePath });
}
[Controller]
public ActionResult GetFile(string path)
{
FileExplorerOperations operation = new FileExplorerOperations();
if (dictionary.ContainsKey(path) && dictionary[path] >= 0)
{
dictionary[path] = 1;
}
else
{
dictionary[path] = 0;
}
FileData result = new FileData();
result.path = path;
result.openedCount = dictionary[path];
return Json(result, JsonRequestBehavior.AllowGet);
}
public ActionResult CloseFile(string path)
{
FileExplorerOperations operation = new FileExplorerOperations();
if (dictionary.ContainsKey(path))
{
dictionary[path] = -1;
}
return null;
} |
|
@*Spreadsheet Dialog*@
@{Html.EJ().Dialog("SpreadsheetDialog").ContentTemplate(@<div style="height: 100%;">
<button onclick="saveSpreadsheet()">Save</button>
@{Html.EJ().Spreadsheet<object>("SpredsheetViewer")
.ScrollSettings(setting => setting.Height(500))
.Render();}
</div>).Width(900).ShowOnInit(false).IsResponsive(true).EnableResize(true).ClientSideEvents(evt => evt.Close("onDialogClose").Resize("onResize")).Render();}
//...
var file, sourcePath;
function OnBeforeOpen(args) {
var viewer = $("#dialogAPI").data("ejDialog"), ssDialog = $("#SpreadsheetDialog").data("ejDialog");
if (args.itemType == "File" && (/\.(docx|xls|xlsx)$/i).test(this._selectedFile)) {
file = args.model.selectedFolder + args.model.selectedItems[0];
if (viewer.isOpen() || ssDialog.isOpen()) {
alert("Already you are viewing another file");
args.cancel = true;
return;
}
$.get("/FileExplorer/GetFile", { path: file })
.done(function (data) {
if (data.openedCount < 1) {
sourcePath = data.path;
file = args.model.selectedFolder + args.model.selectedItems[0];
if ((/\.(docx)$/i).test(sourcePath)) {
//...
}
else {
$.ajax({
url: '@Url.Action("ViewInSpreadsheet", "FileExplorer")',
type: "POST",
dataType: "json",
data: { filePath: file },
success: function (data) {
var ssObj = $("#SpredsheetViewer").data("ejSpreadsheet");
ssDialog.option("title", args.model.selectedItems[0]);
ssDialog.open();
ssObj.loadFromJSON(data);
}
});
}
}
else {
alert("Already (" + data.path + ") file is viewing by other user");
}
});
args.cancel = true;
}
}
function saveSpreadsheet() {
var ssObj = $("#SpredsheetViewer").data("ejSpreadsheet"),
filePath = file, exportProps = ssObj.XLExport.getExportProps();
$.ajax({
type: "POST",
data: { sheetModel: exportProps.model, sheetData: exportProps.data, filePath: filePath },
url: '@Url.Action("ExcelExportOnBtnClick", "FileExplorer")',
success: function (message) {
alert(message);
}
});
}
function onResize(args) {
$("#SpredsheetViewer").ejSpreadsheet("refreshSpreadsheet");
}
|
|
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult ViewInSpreadsheet(string filePath)
{
string path = Server.MapPath(filePath);
var fileStream = System.IO.File.Open(path, FileMode.Open, FileAccess.Read);
ImportRequest importRequest = new ImportRequest();
importRequest.FileStream = fileStream;
var spreadsheetData = Spreadsheet.Open(importRequest);
fileStream.Close();
return Content(spreadsheetData);
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult ExcelExportOnBtnClick(string sheetModel, string sheetData, string filePath)
{
try
{
Stream fileStream = Spreadsheet.Save(sheetModel, sheetData, ExportFormat.XLSX, ExcelVersion.Excel2013);
filePath = Server.MapPath(filePath);
ExcelEngine excelEngine = new ExcelEngine();
IApplication application = excelEngine.Excel;
fileStream.Position = 0;
IWorkbook workbook = application.Workbooks.Open(fileStream);
workbook.SaveAs(filePath);
return Content("Success");
}
catch (Exception ex)
{
return Content(ex.Message);
}
}
|