Today I needed to open several pictures in the Windows Photo Viewer, opening only one instance.
Usually, it's enough to open the image itself directly, and then the user uses the arrows to browse through the images.
However, when the image is in a Temp folder, the arrows are disabled.
The alternative is to open the container folder, and the arrows are then enabled.
Here is my code in VB :
Private Sub BtnLoad_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim filePath As String = "C:\Users\Picsonald\AppData\Local\Temp\SubFolder\photo1.jpg"
Dim directoryPath As String = "C:\Users\Picsonald\AppData\Local\Temp\SubFolder"
OpenPhotoViewer(filePath) ' Open the picture, but arrow are disabled (cause of Temp folder ?) :(
OpenPhotoViewer(directoryPath) ' Open a picture located in the directory, and arrow are enabled :) <- Several pictures can be browsed
End Sub
Private Sub OpenPhotoViewer(pathToOpen As String)
' Finding the PhotoViewer.dll full path...
Dim photoViewerPath As String = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles).Replace(" (x86)", String.Empty), "Windows Photo Viewer", "PhotoViewer.dll")
If Not File.Exists(photoViewerPath) Then
photoViewerPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFilesX86), "Windows Photo Viewer", "PhotoViewer.dll")
End If
' Construct arguments to specify element to display
Dim argument As String = String.Concat("""", photoViewerPath, """, ImageView_Fullscreen " + pathToOpen)
Dim psi As ProcessStartInfo = New ProcessStartInfo("rundll32.exe", argument)
psi.UseShellExecute = True
Process.Start(psi) ' Run the Microsoft Photo Viewer
End Sub
And the same code in C# :
private void BtnLoad_Click(object sender, EventArgs e)
{
string filePath = @"C:\Users\Picsonald\AppData\Local\Temp\SubFolder\photo1.jpg";
string directoryPath = @"C:\Users\Picsonald\AppData\Local\Temp\SubFolder";
OpenPhotoViewer(filePath); // Open the picture, but arrow are disabled (cause of Temp folder ?) :(
OpenPhotoViewer(directoryPath); // Open a picture located in the directory, and arrow are enabled :) <- Several pictures can be browsed
}
private void OpenPhotoViewer(string pathToOpen)
{
// Finding the PhotoViewer.dll full path...
string photoViewerPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles).Replace(" (x86)", String.Empty), "Windows Photo Viewer", "PhotoViewer.dll");
if (!File.Exists(photoViewerPath))
{
photoViewerPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFilesX86), "Windows Photo Viewer", "PhotoViewer.dll");
}
// Construct arguments to specify element to display
string argument = string.Concat("\"", photoViewerPath, "\", ImageView_Fullscreen " + pathToOpen);
ProcessStartInfo psi = new ProcessStartInfo("rundll32.exe", argument);
psi.UseShellExecute = true;
Process.Start(psi); // Run the Microsoft Photo Viewer
}
However, there must be a more suitable approach than the one requested by the questioner, because using Windows Explorer, selecting two pictures from a folder that contains several pictures causes the Windows Photo Viewer to browse through these two pictures only.