Get System Icon for any file/folder

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ashutosh Bhawasinka

    Get System Icon for any file/folder

    Hi,
    How can I retrieve the system icon associated with a file/folder so that
    I can show it in the list view adjacent to the file/folder name?

    Regards,
    Ashutosh Bhawasinka
  • Wen Yuan Wang [MSFT]

    #2
    RE: Get System Icon for any file/folder

    Hello Ashutosh,

    According to your description, you want to get the file/folder icon in your
    ..net application, correct? If I misunderstood anything here, please don't
    hesitate to correct me.

    If this is the case, you may refer to the following article. This document
    has detailed sample code about how to get and display file/folder icon in
    managed application by SHGetFileInfo (WinAPI).
    I have tested sample code in that page. I believe it could works fine in
    your application without any change, too. :)


    [Obtaining (and managing) file and folder icons using SHGetFileInfo in C#]

    Hope this helps. Please try the above method and let me know if you have
    any more concern. We are glad to assist you.
    Have a great day,
    Best regards,
    Wen Yuan

    Microsoft Online Community Support
    Delighting our customers is our #1 priority. We welcome your comments and
    suggestions about how we can improve the support we provide to you. Please
    feel free to let my manager know what you think of the level of service
    provided. You can send feedback directly to my manager at:
    msdnmg@microsof t.com.
    =============== =============== =============== =====
    Get notification to my posts through email? Please refer to
    Learn with interactive lessons and technical documentation, earn professional development hours and certifications, and connect with the community.

    ications.
    Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 1 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions or complex
    project analysis and dump analysis issues. Issues of this nature are best
    handled working with a dedicated Microsoft Support Engineer by contacting
    Microsoft Customer Support Services (CSS) at
    http://msdn.microsoft.com/subscripti...t/default.aspx.
    =============== =============== =============== =====
    This posting is provided "AS IS" with no warranties, and confers no rights.

    Comment

    • Ashutosh Bhawasinka

      #3
      Re: Get System Icon for any file/folder

      Thanks!!
      This is exactly what I needed.

      Regards,
      Ashutosh

      Wen Yuan Wang [MSFT] wrote:
      Hello Ashutosh,
      >
      According to your description, you want to get the file/folder icon in your
      .net application, correct? If I misunderstood anything here, please don't
      hesitate to correct me.
      >
      If this is the case, you may refer to the following article. This document
      has detailed sample code about how to get and display file/folder icon in
      managed application by SHGetFileInfo (WinAPI).
      I have tested sample code in that page. I believe it could works fine in
      your application without any change, too. :)
      >

      [Obtaining (and managing) file and folder icons using SHGetFileInfo in C#]
      >
      Hope this helps. Please try the above method and let me know if you have
      any more concern. We are glad to assist you.
      Have a great day,
      Best regards,
      Wen Yuan
      >
      Microsoft Online Community Support
      Delighting our customers is our #1 priority. We welcome your comments and
      suggestions about how we can improve the support we provide to you. Please
      feel free to let my manager know what you think of the level of service
      provided. You can send feedback directly to my manager at:
      msdnmg@microsof t.com.
      =============== =============== =============== =====
      Get notification to my posts through email? Please refer to
      Learn with interactive lessons and technical documentation, earn professional development hours and certifications, and connect with the community.

      ications.
      Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
      where an initial response from the community or a Microsoft Support
      Engineer within 1 business day is acceptable. Please note that each follow
      up response may take approximately 2 business days as the support
      professional working with you may need further investigation to reach the
      most efficient resolution. The offering is not appropriate for situations
      that require urgent, real-time or phone-based interactions or complex
      project analysis and dump analysis issues. Issues of this nature are best
      handled working with a dedicated Microsoft Support Engineer by contacting
      Microsoft Customer Support Services (CSS) at
      http://msdn.microsoft.com/subscripti...t/default.aspx.
      =============== =============== =============== =====
      This posting is provided "AS IS" with no warranties, and confers no rights.
      >

      Comment

      • Wen Yuan Wang [MSFT]

        #4
        Re: Get System Icon for any file/folder

        Hello Ashutosh,

        You are welcome. If you need any further assistance, just feel free to let
        us know again. :)
        We are glad to assist you.

        Have a great day,
        Best regards,
        Wen Yuan

        Microsoft Online Community Support
        Delighting our customers is our #1 priority. We welcome your comments and
        suggestions about how we can improve the support we provide to you. Please
        feel free to let my manager know what you think of the level of service
        provided. You can send feedback directly to my manager at:
        msdnmg@microsof t.com.
        =============== =============== =============== =====
        This posting is provided "AS IS" with no warranties, and confers no rights.


        Comment

        • parez

          #5
          Re: Get System Icon for any file/folder

          On May 6, 5:36 am, v-wyw...@online.m icrosoft.com ("Wen Yuan Wang
          [MSFT]") wrote:
          Hello Ashutosh,
          >
          According to your description, you want to get the file/folder icon in your
          .net application, correct? If I misunderstood anything here, please don't
          hesitate to correct me.
          >
          If this is the case, you may refer to the following article. This document
          has detailed sample code about how to get and display file/folder icon in
          managed application by SHGetFileInfo (WinAPI).
          I have tested sample code in that page. I believe it could works fine in
          your application without any change, too. :)
          >

          [Obtaining (and managing) file and folder icons using SHGetFileInfo in C#]
          >
          Hope this helps. Please try the above method and let me know if you have
          any more concern. We are glad to assist you.
          Have a great day,
          Best regards,
          Wen Yuan
          >
          Microsoft Online Community Support
          Delighting our customers is our #1 priority. We welcome your comments and
          suggestions about how we can improve the support we provide to you. Please
          feel free to let my manager know what you think of the level of service
          provided. You can send feedback directly to my manager at:
          msd...@microsof t.com.
          =============== =============== =============== =====
          Get notification to my posts through email? Please refer tohttp://msdn.microsoft. com/subscriptions/managednewsgrou ps/default.asp...
          ications.
          Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
          where an initial response from the community or a Microsoft Support
          Engineer within 1 business day is acceptable. Please note that each follow
          up response may take approximately 2 business days as the support
          professional working with you may need further investigation to reach the
          most efficient resolution. The offering is not appropriate for situations
          that require urgent, real-time or phone-based interactions or complex
          project analysis and dump analysis issues. Issues of this nature are best
          handled working with a dedicated Microsoft Support Engineer by contacting
          Microsoft Customer Support Services (CSS) athttp://msdn.microsoft. com/subscriptions/support/default.aspx.
          =============== =============== =============== =====
          This posting is provided "AS IS" with no warranties, and confers no rights.
          I was looking for this myself..thanks. .

          Comment

          • parez

            #6
            Re: Get System Icon for any file/folder

            On May 6, 5:36 am, v-wyw...@online.m icrosoft.com ("Wen Yuan Wang
            [MSFT]") wrote:
            Hello Ashutosh,
            >
            According to your description, you want to get the file/folder icon in your
            .net application, correct? If I misunderstood anything here, please don't
            hesitate to correct me.
            >
            If this is the case, you may refer to the following article. This document
            has detailed sample code about how to get and display file/folder icon in
            managed application by SHGetFileInfo (WinAPI).
            I have tested sample code in that page. I believe it could works fine in
            your application without any change, too. :)
            >

            [Obtaining (and managing) file and folder icons using SHGetFileInfo in C#]
            >
            Hope this helps. Please try the above method and let me know if you have
            any more concern. We are glad to assist you.
            Have a great day,
            Best regards,
            Wen Yuan
            >
            Microsoft Online Community Support
            Delighting our customers is our #1 priority. We welcome your comments and
            suggestions about how we can improve the support we provide to you. Please
            feel free to let my manager know what you think of the level of service
            provided. You can send feedback directly to my manager at:
            msd...@microsof t.com.
            =============== =============== =============== =====
            Get notification to my posts through email? Please refer tohttp://msdn.microsoft. com/subscriptions/managednewsgrou ps/default.asp...
            ications.
            Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
            where an initial response from the community or a Microsoft Support
            Engineer within 1 business day is acceptable. Please note that each follow
            up response may take approximately 2 business days as the support
            professional working with you may need further investigation to reach the
            most efficient resolution. The offering is not appropriate for situations
            that require urgent, real-time or phone-based interactions or complex
            project analysis and dump analysis issues. Issues of this nature are best
            handled working with a dedicated Microsoft Support Engineer by contacting
            Microsoft Customer Support Services (CSS) athttp://msdn.microsoft. com/subscriptions/support/default.aspx.
            =============== =============== =============== =====
            This posting is provided "AS IS" with no warranties, and confers no rights.
            How do assigns this icons to ListViews and Tree views.

            Comment

            • parez

              #7
              Re: Get System Icon for any file/folder

              On May 7, 9:36 am, parez <psaw...@gmail. comwrote:
              On May 6, 5:36 am, v-wyw...@online.m icrosoft.com ("Wen Yuan Wang
              >
              >
              >
              [MSFT]") wrote:
              Hello Ashutosh,
              >
              According to your description, you want to get the file/folder icon in your
              .net application, correct? If I misunderstood anything here, please don't
              hesitate to correct me.
              >
              If this is the case, you may refer to the following article. This document
              has detailed sample code about how to get and display file/folder icon in
              managed application by SHGetFileInfo (WinAPI).
              I have tested sample code in that page. I believe it could works fine in
              your application without any change, too. :)
              >

              [Obtaining (and managing) file and folder icons using SHGetFileInfo in C#]
              >
              Hope this helps. Please try the above method and let me know if you have
              any more concern. We are glad to assist you.
              Have a great day,
              Best regards,
              Wen Yuan
              >
              Microsoft Online Community Support
              Delighting our customers is our #1 priority. We welcome your comments and
              suggestions about how we can improve the support we provide to you. Please
              feel free to let my manager know what you think of the level of service
              provided. You can send feedback directly to my manager at:
              msd...@microsof t.com.
              =============== =============== =============== =====
              Get notification to my posts through email? Please refer tohttp://msdn.microsoft. com/subscriptions/managednewsgrou ps/default.asp...
              ications.
              Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
              where an initial response from the community or a Microsoft Support
              Engineer within 1 business day is acceptable. Please note that each follow
              up response may take approximately 2 business days as the support
              professional working with you may need further investigation to reach the
              most efficient resolution. The offering is not appropriate for situations
              that require urgent, real-time or phone-based interactions or complex
              project analysis and dump analysis issues. Issues of this nature are best
              handled working with a dedicated Microsoft Support Engineer by contacting
              Microsoft Customer Support Services (CSS) athttp://msdn.microsoft. com/subscriptions/support/default.aspx.
              =============== =============== =============== =====
              This posting is provided "AS IS" with no warranties, and confers no rights.
              >
              How do assigns this icons to ListViews and Tree views.
              I got that working by using image keys for the ImageList of the List
              view. but now my icons have a weird black border..

              Comment

              • Ashutosh Bhawasinka

                #8
                Re: Get System Icon for any file/folder

                Hi,
                I am currently using the method mentioned in the CodeProject article.
                However there is a problem. Some file icons and all folder icons have a
                black border around them.

                I checked the code & it looked fine. Don't know why this is happening.

                Is there any way I can remove those black border??

                Regards,
                Ashutosh

                Wen Yuan Wang [MSFT] wrote:
                Hello Ashutosh,
                >
                According to your description, you want to get the file/folder icon in your
                .net application, correct? If I misunderstood anything here, please don't
                hesitate to correct me.
                >
                If this is the case, you may refer to the following article. This document
                has detailed sample code about how to get and display file/folder icon in
                managed application by SHGetFileInfo (WinAPI).
                I have tested sample code in that page. I believe it could works fine in
                your application without any change, too. :)
                >

                [Obtaining (and managing) file and folder icons using SHGetFileInfo in C#]
                >
                Hope this helps. Please try the above method and let me know if you have
                any more concern. We are glad to assist you.
                Have a great day,
                Best regards,
                Wen Yuan
                >
                Microsoft Online Community Support
                Delighting our customers is our #1 priority. We welcome your comments and
                suggestions about how we can improve the support we provide to you. Please
                feel free to let my manager know what you think of the level of service
                provided. You can send feedback directly to my manager at:
                msdnmg@microsof t.com.
                =============== =============== =============== =====
                Get notification to my posts through email? Please refer to
                Learn with interactive lessons and technical documentation, earn professional development hours and certifications, and connect with the community.

                ications.
                Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
                where an initial response from the community or a Microsoft Support
                Engineer within 1 business day is acceptable. Please note that each follow
                up response may take approximately 2 business days as the support
                professional working with you may need further investigation to reach the
                most efficient resolution. The offering is not appropriate for situations
                that require urgent, real-time or phone-based interactions or complex
                project analysis and dump analysis issues. Issues of this nature are best
                handled working with a dedicated Microsoft Support Engineer by contacting
                Microsoft Customer Support Services (CSS) at
                http://msdn.microsoft.com/subscripti...t/default.aspx.
                =============== =============== =============== =====
                This posting is provided "AS IS" with no warranties, and confers no rights.
                >

                Comment

                • Wen Yuan Wang [MSFT]

                  #9
                  Re: Get System Icon for any file/folder

                  Hello Ashutosh,
                  Thanks your reply.

                  According to the "Notes" part on CodeProject article, we have to include a
                  manifest file to use icons with alpha channel.
                  =============== =============== =============== =============== =============== =

                  df=90&mpp=25&no ise=3&sort=Posi tion&view=Quick &fr=26&select=3 05145

                  Important Notes:

                  It's taken me a long time to figure this out, but gave me real grief at one
                  point. Windows XP introduced Visual Styles, enabling you to use icons with
                  alpha channel blending to produce nice smooth icons. However, to include
                  support for this you must include a manifest file. Without one, you get a
                  really ugly black border. For more information on including visual styles
                  support, you ought to read the MSDN Article "Using Windows XP Visual Styles
                  With Controls on Windows Forms". As I said, I forgot to include a manifest
                  and it drove me crazy for weeks.
                  =============== =============== =============== =============== =============== =

                  The link which pointed by Auther has down, but we can get it at

                  [Using Windows XP Visual Styles with Controls on Windows Forms]

                  Moreover, if the above method doesn't help, could you let me know which
                  version of VS you are using?(VS 2002/2003/2005 or 2008). I tried it on VS
                  2005 & WinXP. Folder icon works fine, even though I haven't included any
                  manifest file.

                  Hope this helps. Please try the above method and let me know if this method
                  works. I will follow up. We are glad to be of assistance.
                  Have a great day,
                  Best regards,
                  Wen Yuan

                  Microsoft Online Community Support
                  Delighting our customers is our #1 priority. We welcome your comments and
                  suggestions about how we can improve the support we provide to you. Please
                  feel free to let my manager know what you think of the level of service
                  provided. You can send feedback directly to my manager at:
                  msdnmg@microsof t.com.
                  =============== =============== =============== =====
                  This posting is provided "AS IS" with no warranties, and confers no rights.

                  Comment

                  • Ashutosh Bhawasinka

                    #10
                    Re: Get System Icon for any file/folder

                    Hi Wen,
                    Thanks for your reply.

                    I don't want to include any other file's dependency on my application.
                    Is there any way to do it without using the manifest file? I am
                    currently using VS 2005 with SP1( and plan to use VS 2008 once its free
                    of some of the bugs I noticed).

                    I am using small icons in the list view control(detaile d view).

                    Regards,
                    Ashutosh

                    Wen Yuan Wang [MSFT] wrote:
                    Hello Ashutosh,
                    Thanks your reply.
                    >
                    According to the "Notes" part on CodeProject article, we have to include a
                    manifest file to use icons with alpha channel.
                    =============== =============== =============== =============== =============== =

                    df=90&mpp=25&no ise=3&sort=Posi tion&view=Quick &fr=26&select=3 05145
                    >
                    Important Notes:
                    >
                    It's taken me a long time to figure this out, but gave me real grief at one
                    point. Windows XP introduced Visual Styles, enabling you to use icons with
                    alpha channel blending to produce nice smooth icons. However, to include
                    support for this you must include a manifest file. Without one, you get a
                    really ugly black border. For more information on including visual styles
                    support, you ought to read the MSDN Article "Using Windows XP Visual Styles
                    With Controls on Windows Forms". As I said, I forgot to include a manifest
                    and it drove me crazy for weeks.
                    =============== =============== =============== =============== =============== =
                    >
                    The link which pointed by Auther has down, but we can get it at

                    [Using Windows XP Visual Styles with Controls on Windows Forms]
                    >
                    Moreover, if the above method doesn't help, could you let me know which
                    version of VS you are using?(VS 2002/2003/2005 or 2008). I tried it on VS
                    2005 & WinXP. Folder icon works fine, even though I haven't included any
                    manifest file.
                    >
                    Hope this helps. Please try the above method and let me know if this method
                    works. I will follow up. We are glad to be of assistance.
                    Have a great day,
                    Best regards,
                    Wen Yuan
                    >
                    Microsoft Online Community Support
                    Delighting our customers is our #1 priority. We welcome your comments and
                    suggestions about how we can improve the support we provide to you. Please
                    feel free to let my manager know what you think of the level of service
                    provided. You can send feedback directly to my manager at:
                    msdnmg@microsof t.com.
                    =============== =============== =============== =====
                    This posting is provided "AS IS" with no warranties, and confers no rights.
                    >

                    Comment

                    • Wen Yuan Wang [MSFT]

                      #11
                      Re: Get System Icon for any file/folder

                      Hello Ashutosh,

                      Thanks for your reply. But, I still failed to reproduce the issue. Both
                      folder icon and file icon work fine on my side. I didn't get black border
                      in the icon. Do you have any screen-shooting of the issue? If it's
                      possible, we will appreciate if you can send it to us. This could help for
                      us to understanding the whole picture of the issue. You can get me at
                      v-wywang@microsof t.com.

                      Moreover, the following kb article also descripts the way to get file
                      associated icon by SHGetFileInfo function. Could you please also try the
                      code posted on this article to check if the issue still persists?

                      [How to use the SHGetFileInfo function to get the icons that are associated
                      with files in Visual C# .NET]

                      Hope this helps. If you have any more concern, please also free to let us
                      know. We are glad to assist you.
                      Have a great day,
                      Best regards,
                      Wen Yuan

                      Microsoft Online Community Support
                      Delighting our customers is our #1 priority. We welcome your comments and
                      suggestions about how we can improve the support we provide to you. Please
                      feel free to let my manager know what you think of the level of service
                      provided. You can send feedback directly to my manager at:
                      msdnmg@microsof t.com.
                      =============== =============== =============== =====
                      This posting is provided "AS IS" with no warranties, and confers no rights.

                      Comment

                      • Ashutosh Bhawasinka

                        #12
                        Re: Get System Icon for any file/folder

                        Hi Wen,
                        Please have a look at


                        I am following almost the same steps mentioned in the KB.

                        Regards,
                        Ashutosh

                        Wen Yuan Wang [MSFT] wrote:
                        Hello Ashutosh,
                        >
                        Thanks for your reply. But, I still failed to reproduce the issue. Both
                        folder icon and file icon work fine on my side. I didn't get black border
                        in the icon. Do you have any screen-shooting of the issue? If it's
                        possible, we will appreciate if you can send it to us. This could help for
                        us to understanding the whole picture of the issue. You can get me at
                        v-wywang@microsof t.com.
                        >
                        Moreover, the following kb article also descripts the way to get file
                        associated icon by SHGetFileInfo function. Could you please also try the
                        code posted on this article to check if the issue still persists?

                        [How to use the SHGetFileInfo function to get the icons that are associated
                        with files in Visual C# .NET]
                        >
                        Hope this helps. If you have any more concern, please also free to let us
                        know. We are glad to assist you.
                        Have a great day,
                        Best regards,
                        Wen Yuan
                        >
                        Microsoft Online Community Support
                        Delighting our customers is our #1 priority. We welcome your comments and
                        suggestions about how we can improve the support we provide to you. Please
                        feel free to let my manager know what you think of the level of service
                        provided. You can send feedback directly to my manager at:
                        msdnmg@microsof t.com.
                        =============== =============== =============== =====
                        This posting is provided "AS IS" with no warranties, and confers no rights.
                        >

                        Comment

                        • Wen Yuan Wang [MSFT]

                          #13
                          Re: Get System Icon for any file/folder

                          Hello Ashutosh,

                          Thanks for your reply and screen-shooting. It seems like a black shadow. By
                          default, ColorDepth property of ImageList is 8 Bit. To display tansparent
                          color, we would have to change it to 32 bit. Have you ever changed the
                          colorDepth of ImageList to 32 bit in Code or in Designer Mode?
                          Eg: imageList1.Colo rDepth = ColorDepth.Dept h32Bit;

                          On my side, I reproduced the issue after I change ColorDepth of ImageList
                          back to 8 bit.

                          Hope this helps, please try the above method and let me know if this works.
                          We are glad to assist you.

                          Have a great day,
                          Best regards,
                          Wen Yuan
                          Microsoft Online Community Support
                          Delighting our customers is our #1 priority. We welcome your comments and
                          suggestions about how we can improve the support we provide to you. Please
                          feel free to let my manager know what you think of the level of service
                          provided. You can send feedback directly to my manager at:
                          msdnmg@microsof t.com.
                          =============== =============== =============== =====
                          This posting is provided "AS IS" with no warranties, and confers no rights.

                          Comment

                          • Ashutosh Bhawasinka

                            #14
                            Re: Get System Icon for any file/folder

                            Hi Wen,
                            Thanks so much for your help.

                            I must say that you people are really doing great job :)

                            Regards,
                            Ashutosh

                            Wen Yuan Wang [MSFT] wrote:
                            Hello Ashutosh,
                            >
                            Thanks for your reply and screen-shooting. It seems like a black shadow. By
                            default, ColorDepth property of ImageList is 8 Bit. To display tansparent
                            color, we would have to change it to 32 bit. Have you ever changed the
                            colorDepth of ImageList to 32 bit in Code or in Designer Mode?
                            Eg: imageList1.Colo rDepth = ColorDepth.Dept h32Bit;
                            >
                            On my side, I reproduced the issue after I change ColorDepth of ImageList
                            back to 8 bit.
                            >
                            Hope this helps, please try the above method and let me know if this works.
                            We are glad to assist you.
                            >
                            Have a great day,
                            Best regards,
                            Wen Yuan
                            Microsoft Online Community Support
                            Delighting our customers is our #1 priority. We welcome your comments and
                            suggestions about how we can improve the support we provide to you. Please
                            feel free to let my manager know what you think of the level of service
                            provided. You can send feedback directly to my manager at:
                            msdnmg@microsof t.com.
                            =============== =============== =============== =====
                            This posting is provided "AS IS" with no warranties, and confers no rights.
                            >

                            Comment

                            • Wen Yuan Wang [MSFT]

                              #15
                              Re: Get System Icon for any file/folder


                              Welcome, Ashutosh.
                              The pleasure is all mine. :)

                              Have a great day,
                              Best regards,
                              Wen Yuan

                              Microsoft Online Community Support
                              Delighting our customers is our #1 priority. We welcome your comments and
                              suggestions about how we can improve the support we provide to you. Please
                              feel free to let my manager know what you think of the level of service
                              provided. You can send feedback directly to my manager at:
                              msdnmg@microsof t.com.
                              =============== =============== =============== =====
                              This posting is provided "AS IS" with no warranties, and confers no rights.

                              Comment

                              Working...