Tinymce is a fairly common WYSIWYG editor that allows users to purchase an image/file management system or build your own. I want to upgrade my Content Management system from tinymce 2x to 4x. In 4x the images need to be presented to the tinymce call as a json object in the image_list declaration: http://www.tinymce.com/wiki.php/Configuration:image_list
Based on this format, the goal is to have .Net read the image folder and present the title and value as the filename and 'images/filename' of each file. I've worked at it the past few days and I've made some headway but not to the point of a functional sample. This seems like it would be something that others using .Net and Tinymce would want to use if they roll their own image management system (which I have to do in this case).
This example (see link) seems to get close but my test (see code below) returns null values for the title and value. When I tried to include the other two variables in the example I get error messages that the variables are inaccessible or not available. Converting List of Files into JSON array in C#
Here is the C# script I'm trying to use in creating the JSON variable of image references:
<%@ Import Namespace="Newtonsoft.Json" %>
<script runat="server">
public class FileInformation
{
[JsonProperty(PropertyName = "title")]
public string actualFileName {get;set;}
public string value {get;set;}
}
public string image_list()
{
string[] arr = new string[3]; // Initialize
arr[0] = ".jpg"; // Element 1
arr[1] = ".png"; // Element 2
arr[2] = ".gif"; // Element 3
var imgPath = Server.MapPath("~/images/");
var list = new List<FileInformation>();
//string[] fileNames = Directory.GetFiles(imgPath, "*", SearchOption.TopDirectoryOnly);
string[] fileNames = Directory.GetFiles(imgPath);
foreach (string filename in fileNames)
{
FileInfo fileInfo = new FileInfo(filename);
string actualFileName = fileInfo.Name;
string value = fileInfo.Name;
list.Add(new FileInformation(){});
}
var yourJSONString = JsonConvert.SerializeObject(list);
return yourJSONString;
}
...
</script>
Here is the Javascript call in the page:
<script type="text/javascript">
tinymce.init({
image_list: '<%= image_list()%>',
image_class_list: [
{title: 'None', value: ''},
{title: 'Float Right', value: 'img_fright'}
]
});
Abbreviated Source code from the pate where image_list is rendered:
image_list: '[{"title":null,"value":null},{"title":null,"value":null},{"title":null,"value":null}]',
Any thoughts of where this may be going wrong?