diff --git a/web/documentserver-example/csharp-mvc/Scripts/formats.js b/web/documentserver-example/csharp-mvc/Scripts/formats.js
new file mode 100644
index 00000000..e423eeb2
--- /dev/null
+++ b/web/documentserver-example/csharp-mvc/Scripts/formats.js
@@ -0,0 +1,66 @@
+/**
+ *
+ * (c) Copyright Ascensio System SIA 2024
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+class Format {
+ constructor(name, type, actions, convert, mime) {
+ this.name = name;
+ this.type = type;
+ this.actions = actions;
+ this.convert = convert;
+ this.mime = mime;
+ }
+
+ isAutoConvertible() {
+ return this.actions.includes('auto-convert');
+ }
+
+ isEditable() {
+ return this.actions.includes('edit') || this.actions.includes('lossy-edit');
+ }
+
+ isFillable() {
+ return this.actions.includes('fill');
+ }
+}
+
+class FormatManager {
+ formats = [];
+
+ constructor(formats) {
+ if(Array.isArray(formats)) this.formats = formats;
+ }
+
+ findByExtension(extension) {
+ return this.formats.find(format => format.name == extension);
+ }
+
+ isAutoConvertible(extension) {
+ let format = this.findByExtension(extension);
+ return format !== undefined && format.isAutoConvertible();
+ }
+
+ isEditable(extension) {
+ let format = this.findByExtension(extension);
+ return format !== undefined && format.isEditable();
+ }
+
+ isFillable(extension) {
+ let format = this.findByExtension(extension);
+ return format !== undefined && format.isFillable();
+ }
+}
\ No newline at end of file
diff --git a/web/documentserver-example/csharp-mvc/Scripts/jscript.js b/web/documentserver-example/csharp-mvc/Scripts/jscript.js
index 4399c79a..d74be36c 100644
--- a/web/documentserver-example/csharp-mvc/Scripts/jscript.js
+++ b/web/documentserver-example/csharp-mvc/Scripts/jscript.js
@@ -17,6 +17,27 @@
*/
var directUrl;
+var formatManager;
+
+window.onload = function () {
+ fetch("webeditor.ashx?type=formats")
+ .then((response) => response.json())
+ .then((data) => {
+ if (data.formats) {
+ let formats = [];
+ data.formats.forEach(format => {
+ formats.push(new Format(
+ format.Name,
+ format.Type,
+ format.Actions,
+ format.Convert,
+ format.Mime
+ ));
+ });
+ formatManager = new FormatManager(formats);
+ }
+ })
+}
if (typeof jQuery != "undefined") {
jq = jQuery.noConflict();
@@ -103,7 +124,7 @@ if (typeof jQuery != "undefined") {
var posExt = fileName.lastIndexOf('.');
posExt = 0 <= posExt ? fileName.substring(posExt).trim().toLowerCase() : '';
- if (ConverExtList.indexOf(posExt) == -1) {
+ if (!formatManager.isAutoConvertible(posExt)) {
jq("#step2").addClass("done").removeClass("current");
loadScripts();
return;
@@ -184,10 +205,10 @@ if (typeof jQuery != "undefined") {
jq("#beginView, #beginEmbedded").removeClass("disable");
var fileName = jq("#hiddenFileName").val();
- var posExt = fileName.lastIndexOf('.');
+ var posExt = fileName.lastIndexOf('.') + 1;
posExt = 0 <= posExt ? fileName.substring(posExt).trim().toLowerCase() : '';
- if (EditedExtList.indexOf(posExt) != -1 || FillExtList.indexOf(posExt) != -1) {
+ if (formatManager.isEditable(posExt) || formatManager.isFillable(posExt)) {
jq("#beginEdit").removeClass("disable");
}
};
diff --git a/web/documentserver-example/csharp-mvc/Views/Home/Index.aspx b/web/documentserver-example/csharp-mvc/Views/Home/Index.aspx
index 639ab4c9..fdf0ec31 100644
--- a/web/documentserver-example/csharp-mvc/Views/Home/Index.aspx
+++ b/web/documentserver-example/csharp-mvc/Views/Home/Index.aspx
@@ -373,9 +373,6 @@
<%: Scripts.Render("~/bundles/jquery", "~/bundles/scripts") %>
diff --git a/web/documentserver-example/csharp-mvc/WebEditor.ashx.cs b/web/documentserver-example/csharp-mvc/WebEditor.ashx.cs
index 8eaa1897..f3c0bb01 100644
--- a/web/documentserver-example/csharp-mvc/WebEditor.ashx.cs
+++ b/web/documentserver-example/csharp-mvc/WebEditor.ashx.cs
@@ -87,6 +87,9 @@ namespace OnlineEditorsExampleMVC
case "reference":
Reference(context);
break;
+ case "formats":
+ Formats(context);
+ break;
}
}
@@ -974,6 +977,25 @@ namespace OnlineEditorsExampleMVC
return history;
}
+ // return all the supported formats
+ private static void Formats(HttpContext context)
+ {
+ try
+ {
+ Dictionary data = new Dictionary
+ {
+ { "formats", FormatManager.All() }
+ };
+ context.Response.ContentType = "application/json";
+ var jss = new JavaScriptSerializer();
+
+ context.Response.Write(jss.Serialize(data));
+ }
+ catch (Exception e)
+ {
+ context.Response.Write("{ \"error\": \"" + e.Message + "\"}");
+ }
+ }
}
}
\ No newline at end of file
diff --git a/web/documentserver-example/csharp/Default.aspx b/web/documentserver-example/csharp/Default.aspx
index 4f207cfb..a0f027e2 100644
--- a/web/documentserver-example/csharp/Default.aspx
+++ b/web/documentserver-example/csharp/Default.aspx
@@ -380,12 +380,8 @@
+
-