Search code examples
c#.netwindowsprocessphotos

How launch batch photos/images in gallery view in C#


For a project I have folders of images. An example folder might be ImagesOfDogs, and the images inside would be sequentially named (1.png, 2.png, etc.). I have a button, and when I press this button I want to open all of the images in a folder at once, in one window. I could make my own window, but I would rather use the default Windows program so the user can edit the photos. This would look like the following (just imagine that black thing is a really cute dog pic): enter image description here

Let's say the path to a folder is a string titled sPathToFolderOfDogs. On my button click, I want a method like this:

private void OpenCoolPicsOfDogs()
{
    Process.Start(sPathToFolderOfDogs);
}

Except that will open all enclosed files in an image viewing application, preferably whichever is the user default. I have tried:

Process.Start("PictureViewer", sPathToFolderOfDogs);

...which opens PictureViewer and does not open my photos in PictureViewer,

Process.Start(sPathToParticularImage1);
Process.Start(sPathToParticularImage2);
etc etc

...which opens each in a new window, and possibly most creatively/desperately:

String[] arrayOfAllMyPathsToParticularImagesInTheFolder;
(put all the strings in the array)
Process.Start(arrayOfAllMyPathsToParticularImagesInTheFolder);

Which just crashed. I know opening folders in applications through Process.Start should be possible because it is done in the docs here.* Is there a way to do it with images?

*relevant code from link:

       // Start Internet Explorer. Defaults to the home page.

        Process.Start("IExplore.exe");

        // Display the contents of the favorites folder in the browser.

        Process.Start(myFavoritesPath);

Thanks!


Solution

  • It turns out my question was a duplicate. However, I am not deleting it, as the powers that be suggest it is best to keep duplicates up as a "signpost" informing future searchers where the true path lies.

    Here is the answer to my question (or more specifically, about half a dozen equally functional answers to my question).

    TL;DR: The solution I am now using is from @bruceatk in the above link.