Tuesday, January 3, 2012

Deploy custom images to SharePoint2010

We can deploy custom images to SharePoint 2010 in the same as Custom application pages.
SharePoint 2010 stores images in the following directory.
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\IMAGES . But you can access through virtual directory http://[Server Name]/_layouts/images/.

Also you can check out some posts on:

- Use Gridview to Bind list data in SharePoint 2010

- Custom timer job sharepoint 2010

- Error Occurred in Deployment Step Recycle IIS Application Pool error in SharePoint

Here we will see how can we deploy through Visual Studio 2010. To deploy images to SharePoint first you need to create an Empty SharePoint project by choosing from the SharePoint 2010 template list in Visual Studio 2010, just same way as you create in case of Custom application pages.

Next Select the project Add -> SharePoint "Images" Mapped Folder as shown in the figure below.


Microsoft provided these options to make easier for developers. After choosing this SharePoint creates an Images folder inside the project and also it will create another folder with the same name as the name of the project as shown in the figure below.

Now you are done. Right click on the solution then rebuild the project. After successfully rebuild Right click on the solution again and Deploy Solution.

Now if you will check in C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\IMAGES this folder then, there should be a subdirectory with same name as of you project should present and inside that sub directory your images should present. You can access the images as below:
http://[Server Name]/_layouts/images/[Your Sub Dir Name]/imagename.png(this is your image name).

If you want to deploy it using wsp then follow this link.

Download the project here.

1 comment:

  1. Just wanted to add that this will work for a Farm Solution. But for a Sandbox solution, make a feature to deploy to "Images" folder in "Style Library" of the site collection.

    ReplyDelete