/// Get File Type for given file.
///
/// Pass the path of file
///
This method returns Associated file type like :-
.pdf = Adobe Acrobat Document
.txt = Text Document
private string GetAssociatedFileType(string filePath)
{
private const string STRING_SPACE = " ";
string extension = string.Empty;
if (!string.IsNullOrEmpty(filePath))
{
string extension = Path.GetExtension(filePath);
}
RegistryKey key = Registry.ClassesRoot.OpenSubKey(extension);
while (key != null)
{
string name = (string)key.GetValue(null);
if (name == null)
{
return extension + STRING_SPACE + "File";
}
RegistryKey tempKey = Registry.ClassesRoot.OpenSubKey(name);
if (tempKey == null)
{
return name;
}
key = tempKey;
}
return extension + STRING_SPACE + "File";
}
0 comments:
Post a Comment