I am developing a C# WPF application using .NET 6 in Visual Studio 2022, with a SQL Server 2008 R2 database. My database contains a table GRADE_CUST_GRP with a column GCPS of type image, where files of various types are stored without any file extension information. I am looking for a way to retrieve and open these files in a WPF application, similar to how "SQL Image Viewer" dynamically displays content based on the file's actual type (e.g., displaying an image for picture files, or opening a document for PDF/text files), without prior knowledge of the file type. The challenge is to detect the file type from the byte content and then display or open the file appropriately in the WPF application. I am open to using third-party libraries or any .NET functionality that could help achieve this. However, attempts to use the MimeType class for recognizing the file type were unsuccessful, as it did not recognize the file type correctly. Here is the SQL definition for the relevant part of the table:
CREATE TABLE [dbo].[GRADE_CUST_GRP]
(
[GCGRPID] [int] NOT NULL,
[GCPS] [image] NULL
)
What I have tried:
How can I achieve the functionality of opening and viewing files directly from the database in my WPF application, regardless of their type, as "SQL Image Viewer" does? Any suggestions for libraries or approaches for detecting file types and handling them appropriately in WPF would be greatly appreciated, especially considering the limitations I encountered with the MimeType class and the diverse file types, including OLE Object packages. (From MS Access) Please provide code examples or guidance on how to implement this feature.
PS : There is a special old project for which I have to do this, I have no choice, but for our main project, I use SQL Server 2019