Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
340
How to set the icon of a file in listview without accessing the file
posted

Hello-

 I am using the ultraListView to display a list of files along with some other information. I purchased the Infragistics training and went through the tutorials about how to set the icon of the file in the listview by using SHGetFileInfo and that works great. However, I have one problem. In my application, the file list that I am concerned with is stored in a database. So, the user does not have direct access to the file (the files are in a zip archive on the folder, when the user clicks I am extracting that particular file from the zip on the server (for speed issues over VPN). 

So, my question is, is it possible to get the icon associated with a particular file extension without having direct access to that file and performing that SHGetFileInfo call? 

 

TIA!!

Parents
No Data
Reply
  • 17259
    Offline posted

    Yes, there is. I don't know how you got the file icon, but that's what I did to get the file extension icon:

    public static System.Drawing.Icon GetFileTypeIcon(

    string extension,

    EnumIconSize size,bool addLinkOverlay)

    {

    EnumFileInfoFlags flags =

    EnumFileInfoFlags.ICON | EnumFileInfoFlags.USEFILEATTRIBUTES;

    // add link overlay if requested

    if (addLinkOverlay)

    {

    flags |=
    EnumFileInfoFlags.LINKOVERLAY;

    }

    // set size

    if (size == EnumIconSize.Small)

    {

    flags |=
    EnumFileInfoFlags.SMALLICON;

    }

    else

    {

    flags |=
    EnumFileInfoFlags.LARGEICON;

    }

    string fileType = "*." + extension;ShellFileInfo shellFileInfo = new ShellFileInfo();

    SHGetFileInfo(

    fileType,

    conFILE_ATTRIBUTE_NORMAL,

    ref shellFileInfo,

    (uint)System.Runtime.InteropServices.Marshal.SizeOf(shellFileInfo),

    (uint)flags);

    // deep copy

    System.Drawing.Icon icon =

    (System.Drawing.Icon)System.Drawing.Icon.FromHandle(shellFileInfo.hIcon).Clone();

    // release handle

    DestroyIcon(shellFileInfo.hIcon);

    return icon;

    }

Children
No Data