Upload Documents to a DocLib using features(Module)

on Wednesday, October 28, 2009

Suppose You have created a DocumentLibrary named  "AddNewItems" and you want to upload few items to that document library.

Following is the content of the elementmanifest.xml file.


<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Module List="101" Name="AddNewItems" Url="AddNewItems/sample">
    <File IgnoreIfAlreadyExists ="true" Path="a.txt"
           Type="GhostableInLibrary" Url="AddNewItems2/sample2/a1/a1.txt">
      <Property Name="Title" Value="abc"></Property>
      <Property Name="empname" Value="Hello"></Property>
    </File>
  </Module>
</Elements>

Things to note:
Url attribute in the Module element should start with the listname into which you want to upload the documents. You can also put more values in that element (like "listname/sample") if you want to create folders inside document library.

Column Values: If you want to set column values you should use Properties element like shown above. I wanted to populate "empname" property with value "Hello".

Type should always have "GhostableInLibrary" for items in Document Library.

Url in File element is a virtual path for the file. It will create folders if they don't exist.

0 comments: