title: How to add sitecore items to a sitecore package programatically using Sitecore.Install.PackageGenerator?
body: <p>I want to programatically create package of all items in my sitedata folder using  Sitecore.Install.PackageGenerator . I am able to add Uri property of each item to package but cannot figure how to add the item itself. Please find below my code snippet. </p>
  
  <pre><code>using (new Sitecore.SecurityModel.SecurityDisabler())
          {
              Sitecore.Data.Database db = Sitecore.Configuration.Factory.GetDatabase("web");
              Sitecore.Install.PackageProject document = new Sitecore.Install.PackageProject();
  
              document.Metadata.PackageName = "SitecoreBackup"+DateTime.Now;
              document.Metadata.Author = "PrePublishEvent";
  
              Sitecore.Install.Items.ExplicitItemSource source = new Sitecore.Install.Items.ExplicitItemSource(); //Create source – source should be based on BaseSource  
  
              source.Name = "SitecoreBackupSource";
              Sitecore.Data.Items.Item[] items = db.Items.Database.SelectItems("/sitecore/content/Sites/mysite/Site Data/*");
  
              foreach (Sitecore.Data.Items.Item item in items)
              {
                 // source.Entries.Insert(0,item.ToString);
                  source.Entries.Add(new Sitecore.Install.Items.ItemReference(item.Uri, false).ToString());
              }
  
              document.Sources.Add(source);
              document.SaveProject = true;
  
              //path where the zip file package is saved  
              using (Sitecore.Install.Zip.PackageWriter writer = new Sitecore.Install.Zip.PackageWriter("/data/packages/" + "SitecoreBackup" + DateTime.Now.Ticks.ToString() + ".zip"))
              {
                  Sitecore.Context.SetActiveSite("shell");
                  writer.Initialize(Sitecore.Install.Installer.CreateInstallationContext());
                  Sitecore.Install.PackageGenerator.GeneratePackage(document, writer);
                  Sitecore.Context.SetActiveSite("website");
              }}
  </code></pre>