Thursday, October 18, 2012

How to insert an image, page, video or file in a SharePoint site Document Library through a feature.

Suppose you want to upload an image or any file on a site document library on feature activated. It will get uploaded on that gallery and then you can use this image path in your code. Now you can change image without changing its name and can change it. Steps are as follows:

Steps for adding an image in Document Library:

1.) First you need to open a SharePoint type project in Visual Studio 2010. Now add a new Module to project and name it as "SiteCollectionImages" and within it. Now add a new folder within this module and rename this folder as "Document Library Name". Put this image inside this folder.

2.) Now in Elements.xml file of module and made elements.xml file entry should be like this :

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Module  Name="SiteCollectionImages" Url="SiteCollectionImages" >
      <File Path="
Document Library Name/Default.jpg" Url="Default.jpg" Type="GhostableInLibrary" />
  </Module>
</Elements>


Here SiteCollectionImages is the Module Name and document library name is name of the doc lib in which you want to keep this image or file.

3.) Now right click on this particular image and select properties and in properties select its Deployment Location. In deployment location path should be like this "Document Library Name/". Now save it.

4.) Now activate the feature added by default and this image will be uploaded into your doc library. You can upload any static file (which do cont contains code) like this and then use it across SharePoint site.



No comments:

Post a Comment