Recently used files—Command, MultiItem, and ComboBox
[C#]
RecentFilesRegistryHelper.cs
using System;
using System.Collections.Generic;
using System.Text;
using ESRI.ArcGIS.Framework;
using Microsoft.Win32;
namespace RecentFilesCommandsCS
{
/// <summary>
/// Helper class to process recent file lists stored in the registry
/// </summary>
class RecentFilesRegistryHelper
{
const string RecentFileRegistryKeyPath = @"Software\ESRI\{0}\Recent File List";
public static string[] GetRecentFiles(IApplication app)
{
List<string> recentFilePaths = new List<string>();
//Read the registry to get the recent file list
string openKey = string.Format(RecentFileRegistryKeyPath, app.Name);
RegistryKey recentListKey = Registry.CurrentUser.OpenSubKey(openKey);
if (recentListKey != null)
{
string[] listNames = recentListKey.GetValueNames();
foreach (string name in listNames)
{
string fileName = recentListKey.GetValue(name, string.Empty).ToString();
if (!string.IsNullOrEmpty(fileName))
recentFilePaths.Add(fileName);
}
}
return recentFilePaths.ToArray();
}
}
}
[Visual Basic .NET]
RecentFilesRegistryHelper.vb
Imports System.Collections.Generic
Imports Microsoft.Win32
Module RecentFilesRegistryHelper
Const RecentFileRegistryKeyPath As String = "Software\ESRI\{0}\Recent File List"
''' <summary>
''' Helper function to process recent file lists stored in the registry
''' </summary>
Public Function GetRecentFiles(ByVal app As ESRI.ArcGIS.Framework.IApplication) As String()
Dim recentFilePaths As List(Of String) = New List(Of String)
'Read the registry to get the recent file list
Dim openKey As String = String.Format(RecentFileRegistryKeyPath, app.Name)
Dim recentListKey As RegistryKey = Registry.CurrentUser.OpenSubKey(openKey)
If Not recentListKey Is Nothing Then
Dim listNames As String() = recentListKey.GetValueNames()
For Each name As String In listNames
Dim fileName As String = recentListKey.GetValue(name, String.Empty).ToString()
If Not String.IsNullOrEmpty(fileName) Then
recentFilePaths.Add(fileName)
End If
Next
End If
Return recentFilePaths.ToArray()
End Function
End Module