How to use Visual Studio to add an icon to your Web Part in SharePoint development goes straight to the chase. Take Hello world for example. 1. Open vs as Administrator and create a new blank SharePoint project. Click OK. Deployed as a farm solution. 2. Right-click the item to add a new item--web part, name Helloworldwebpart. 3. Edit code: Before deployment, here I want to add an icon to the Web Part. Each Web Part has two icons: one identifies the Web Part in the Web Part gallery, and one identifies the Web Part on the page. Using an icon is a simple trick that can enhance your Web parts and often requires little code. The Web Part definition contains two properties that specify the icon, and one is CatalogIconImageUrl, which specifies the URL location of the icon file. Must be a 16x16 pixel picture, png/gif or JPEG format. This icon identifies the Web Part in the Web Part gallery, and it is strongly recommended to use the icon here, which will help your users discover this Web Part and give a professional impression. The second icon is Titleiconimageurl, which you can use to display to the left of the Web Part title bar. Can be the same size as the first icon. In fact, it is not recommended to use the icon here. Typically, it affects the visual effects of Web Parts. If no other Web Part has an icon, it has a negative effect. You can specify an icon in a. webpart file, or overwrite it in a Web Part class. Of course, the simplest thing to do is to modify it in a. webpart file. First you want to add an icon to the project. Right-click the project and select Add--sharepoint Picture Map folder. VS will add folders to the project, create subfolders, and name your project name. Here you want to add the icon picture file.
Then you want to edit the. WebPart file: 4. Click Build--Deploy the solution. 5. Add a Web Part to a SharePoint page to see: