Shiku

Hi - I have the following questions with respect to files. I have access to files and folders via the DirectoryInfo and FileInfo.

1. How can we access the icons associated with files These are the icons we would see in Explorer.

2. How can we identify what application a file is associated with

3. How can we tell the "File Type" for a file This is one of the columns you would see in Explorer.

4. How would you access metadata for a file - especially music and picture files: example. artist, song, album names or date picture taken.

5. Is there a way to identify caching files What I mean is being able to identify files like "thumbs.db". Typically music and picture management applications will create files equivalent in function to "thumbs.db". How would we identify them My suspision is we would have do it the hard way - simply research all the popular applications and maintain the list.

I would appreciate pointers to articles, links to sites where I might be able to research and learn how i can accomplish the above tasks. If someone has already solved these problems, I would love to see solutions. Thanks in advance!

SSL




Re: Visual C# General File access questions

Navaneeth

shiku wrote:

How can we access the icons associated with files These are the icons we would see in Explorer.


http://www.codeguru.com/csharp/csharp/cs_misc/icons/article.php/c4261/

shiku wrote:

How would you access metadata for a file - especially music and picture files: example. artist, song, album names or date picture taken.


http://mark.michaelis.net/Blog/RetrievingMetaDataFromJPEGFilesUsingC.aspx

Hope this helps





Re: Visual C# General File access questions

~rabin

Hey Shikhu,
That's a heck lot of questions. I don't think there are classes in .NET to handle any of your needs. That means you have to use the P/Invoke to call Win32 functions to do your jobs. Google a bit, I'm sure you'll find out ways to do these.

I had once done extracting icons from files using PInvoke. Here's the solution to your problem no 1:
dotnetjunkies.com/WebLog/malio/archive/2004/10/04/27603.aspx

Hope others will post for your other questions as well.





Re: Visual C# General File access questions

Ji Cheng Wang - MSFT

Hi SSL,

For your five questions, please try to check out the following for reference.

shiku wrote:

1. How can we access the icons associated with files These are the icons we would see in Explorer

Please try to refer to NavaneethNavaneeth's reply and rabin's reply.

shiku wrote:

2. How can we identify what application a file is associated with

If you would like to identify what application is associated with a file, try to check out this KB for reference - http://support.microsoft.com/kb/257592

If you would like to associate a file type on the system with your application, you can try to check out this article for reference - http://www.codeproject.com/dotnet/System_File_Association.asp

shiku wrote:

3. How can we tell the "File Type" for a file This is one of the columns you would see in Explorer.

As far as I know, you can try to get the File type using SHGetFileInfo API. Here some sample codes in C# for your reference as follows:

Code Block

SHFILEINFO shinfo = new SHFILEINFO();
IntPtr i = Win32.SHGetFileInfo(@"d:\temp\test.xls", 0, ref
shinfo,(uint)Marshal.SizeOf(shinfo),Win32.SHGFI_TY PENAME);
string s = Convert.ToString(shinfo.szTypeName.Trim());

[StructLayout(LayoutKind.Sequential)]
public struct SHFILEINFO
{
public IntPtr hIcon;
public IntPtr iIcon;
public uint dwAttributes;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string szDisplayName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
public string szTypeName;
};

class Win32
{
public const uint SHGFI_DISPLAYNAME = 0x00000200;
public const uint SHGFI_TYPENAME = 0x400;
public const uint SHGFI_ICON = 0x100;
public const uint SHGFI_LARGEICON = 0x0; // 'Large icon
public const uint SHGFI_SMALLICON = 0x1; // 'Small icon

[DllImport("shell32.dll")]
public static extern IntPtr SHGetFileInfo(string pszPath, uint
dwFileAttributes, ref SHFILEINFO psfi, uint cbSizeFileInfo, uint uFlags);

}

Try to check out this thread for details - http://www.thescripts.com/forum/thread258572.html

shiku wrote:

4. How would you access metadata for a file - especially music and picture files: example. artist, song, album names or date picture taken.

If you would like to access the image metadata, you can try to check out this article for reference - http://www.codeproject.com/dotnet/ImageInfo.asp

About file metadata access, you can try to check out the following threads for reference:

http://www.thescripts.com/forum/thread255748.html

http://www.thescripts.com/forum/thread498388.html

shiku wrote:

5. Is there a way to identify caching files What I mean is being able to identify files like "thumbs.db". Typically music and picture management applications will create files equivalent in function to "thumbs.db". How would we identify them My suspision is we would have do it the hard way - simply research all the popular applications and maintain the list.

About file caching, I recommend you check out this MSDN document for reference - http://msdn2.microsoft.com/en-us/library/aa364218.aspx

Hope this helps,

Regards,

This response contains links reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you.
Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.
There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.






Re: Visual C# General File access questions

shiku

Thanks Navneeth, rabin and Ji Cheng Wang!

I have tried the solutions to the following and they work:

1. How can we access the icons associated with files These are the icons we would see in Explorer

3. How can we tell the "File Type" for a file This is one of the columns you would see in Explorer

I have not yet tried the remaining solutions. I will post them as I implement. Thanks again all, and for your detailed response Ji Cheng Wang!

SSL