As i am able get Correct file Type for image as JPEG Image. But i can get file type for pdf document or sql file. I am using below code:
public String Type
{
get
{
return GetType(Path.GetExtension(_document.DocumentPath));
}
}
public static string ReadDefaultValue(string regKey)
{
using (var key = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(regKey, false))
{
if (key != null)
{
return key.GetValue("") as string;
}
}
return null;
}
public string GetType(string ext)
{
if (ext.StartsWith(".") && ext.Length > 1) ext = ext.Substring(1);
var retVal = ReadDefaultValue(ext + "file");
if (!String.IsNullOrEmpty(retVal)) return retVal;
using (var key = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey("." + ext, false))
{
if (key == null) return "";
using (var subkey = key.OpenSubKey("OpenWithProgids"))
{
if (subkey == null) return "";
var names = subkey.GetValueNames();
if (names == null || names.Length == 0) return "";
foreach (var name in names)
{
retVal = ReadDefaultValue(name);
if (!String.IsNullOrEmpty(retVal)) return retVal;
}
}
}
return "";
}
As i have seen that there is no "OpenWithProgids" subkey in .pdf file in regedit. so what can do to get these file types.
For Example
In win 7
file type listed with file name and with other information , I want that same file type in my application I am able to xps document but not other document