ASP .Net Tinymce external_image_list.js creator for images in the images folder

Hi,

I'm looking for a asp .net server page that generates the external_image_list.js file for tinymce.  I found this sample, but not really sure how to implement. We have to upload files with a custom uploader so we can track who uploaded the file.  Once the files are in the images folder, i need an easy way for users to select those images and insert them into the page using the Tinymce interface.  I have three different folders that I will need to reference and they differ based on which page is called into the editor.  The folders are

\images
\folder1\images
\folder2\images

There is a url variable pagetype that sets the folder to read the pages and could be used to either switch the editor and the .js file or be dynamic in the asp .net file.  For example

?pagetype=normal for \images
?pagetype=folder1 for \folder1\images
?pagetype=folder2 for \folder2\images

Here is the sample I found and not sure how to implement:
http://stackoverflow.com/questions/8570016/getting-a-tinymce-dropdown-image-list-in-an-mvc3-application
atljarmanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

atljarmanAuthor Commented:
I forgot mention that I need .jpg, .gif, and png files.  The example only shows .jpg
0
atljarmanAuthor Commented:
Ok.  I got this to produce a javascript file array:

var tinyMCEImageList = new Array(["yes.jpg", "/Content/img/yes.jpg"]);

Open in new window


Does anyone know how to modify to get .png and .gif also?  I've had a hard time getting these two to work.
0
atljarmanAuthor Commented:
Ok, this adds the other extensions.  

public List<string> populateList(string path, params string[] extensions)
{
    List<string> list = new List<string>();
    FileInfo fi = new FileInfo(path);
    DirectoryInfo di = fi.Directory;
    FileSystemInfo[] fsi = di.GetFiles();
    foreach (FileSystemInfo info in fsi)
        foreach (var ext in extensions)
            if (info.Extension == ext)
                list.Add(info.Name);
            else if (info.Extension == ".gif")
                list.Add(info.Name);
            else if (info.Extension == ".png")
                list.Add(info.Name);
            //else if (info.Extension == ".jpg")
            //    list.Add(info.Name);
    return list;
}

//Called from

    List<string> fileList = populateList(imgPath, ".jpg");

Open in new window




However, how would you modify it so that you could just pass the string like this:

    List<string> fileList = populateList(imgPath, ".jpg|.png|.gif");

Open in new window



I would like to create a similar function to create a javascript list of documents.
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

atljarmanAuthor Commented:
I believe this will do it:

    string[] arr = new string[3]; // Initialize
    arr[0] = ".jpg";               // Element 1
    arr[1] = ".png";               // Element 2
    arr[2] = ".gif";             // Element 3

    List<string> fileList = populateList(imgPath, arr);

Open in new window

0
GaryCommented:
Call your function with the multiple extensions as you have exampled (".jpg|.png|.gif") and then to check if the files are of the allowed types use

...
foreach (FileSystemInfo info in fsi)

if (extensions.Contains(info.Extension))
list.Add(info.Name);

...

Open in new window

0
atljarmanAuthor Commented:
Thanks Gary,

I think the solution I tried worked.  I'm going to make a new function for documents and test that to see if it works.
0
GaryCommented:
Maybe I misunderstood I thought you were trying to do the extension check in one go
0
atljarmanAuthor Commented:
I am... just not sure i understand your suggestion.  Been working on this off and on all day and really just want a solution that works.  I might be able to understand your suggestion later and implement, but right now i'm drawing a blank.  I really appreciate your help though.
0
GaryCommented:
Try your code like this
public List<string> populateList(string path, params string[] extensions)
{
    List<string> list = new List<string>();
    FileInfo fi = new FileInfo(path);
    DirectoryInfo di = fi.Directory;
    FileSystemInfo[] fsi = di.GetFiles();
    foreach (FileSystemInfo info in fsi){
// if extensions which equals ".jpg|.png|.gif" contains this file extension then add
        if (extensions.Contains(info.Extension))
            list.Add(info.Name);
}

    return list;
}

//Called from

    List<string> fileList = populateList(imgPath, ".jpg|.png|.gif"); 

Open in new window

0
atljarmanAuthor Commented:
Gary,

Thanks.  Will try In the am.  Looks promising.
0
atljarmanAuthor Commented:
No go.  Both the doc file and the image file the listed files are empty (none).  Is there an easier way for an string-array builder than this:

    string[] arr = new string[3]; // Initialize
    arr[0] = ".jpg";               // Element 1
    arr[1] = ".png";               // Element 2
    arr[2] = ".gif";  

Open in new window


calling that with this works (but its not in one line of code:

    List<string> fileList = populateList(imgPath, arr);

Open in new window


This will be called every time the user uploads a file, which I may ask you about a little later as I wan't to switch the folder by url variable so I only have to write one procedure to cover the 6 different folders (docs and images 3 each)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GaryCommented:
No reason it shouldn't work, add some logic testing

  foreach (FileSystemInfo info in fsi){
response.write info.Extension & "-" & extensions;
// if extensions which equals ".jpg|.png|.gif" contains this file extension then add
        if (extensions.Contains(info.Extension))
            list.Add(info.Name);
0
atljarmanAuthor Commented:
Couldn't get your suggestion to work but know that you would have worked through it with me.  Needed to move on and the solution I provided above is the one that worked. Thanks for the help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.