How to read multiple embedded ressource names with a search pattern in C# and VB.NET

To read multiple embedded ressources with a search pattern in C# and VB.NET you can use the following snippet.

Sample C#

public List<String> ReadEmbeddedRessources(string pattern)
{
	var res = new List<String>();
	try
	{
		var myAssembly = Assembly.GetExecutingAssembly();
		var resList = myAssembly.GetManifestResourceNames();
		res.AddRange(resList.Where(resListItem => resListItem.Contains(pattern)));
		return res;
	}
	catch (Exception ex)
	{
		//handle the exception your way
		return new List<String>();
	}
}

Sample VB.NET

Public Function ReadEmbeddedRessources(ByVal pattern As String) As List(Of String)
        Dim res As var = New List(Of String)
        Try 
            Dim myAssembly As var = Assembly.GetExecutingAssembly
            Dim resList As var = myAssembly.GetManifestResourceNames
            res.AddRange(resList.Where(() => {  }, resListItem.Contains(pattern)))
            Return res
        Catch ex As Exception
            'handle the exception your way
            Return New List(Of String)
        End Try
    End Function

Please Share us:
Please rate this snippet

One thought on “How to read multiple embedded ressource names with a search pattern in C# and VB.NET

Leave a Reply