Monday, 16 January 2017

Bar Code in Sharepoint

Bar Code Feature :- We have two option to enable Bar Code Feature in Document library 

1. Out Of the Box Feature 
2. Custom Programmatically

1. Use the Information Management Policy Feature to enable bar code on documents by Out Of the Box Feature

 Go to Document Library >>Library Settings>>Click on Information Management Policy >>
there are many option >> Select BarCode Checkbox >> Click Ok >> ModifiView >> Add Two Bar Codes Columns in View >>Click OK

Now Add documents in documents library Bar Code will  come automatically.


2. Using Programmatically

Enable the Feature On Document Library and use the below code for custom Bar Codes






using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using System.Drawing;
using Microsoft.Office.RecordsManagement.PolicyFeatures;

namespace SetBarCodeValue
{
    class Program
    {
        static void Main(string[] args)
        {
            //Define the parameter values: Site collection URL
            string siteURL = "http://example/sites/siteCOllectionName";

            using(SPSite site=new SPSite(siteURL))
            {
                using (SPWeb web = site.RootWeb)
                  {
                      //Get a document library
                      SPList list = web.Lists["Design Documents"];
                      //Get an Item
                      SPListItem item = list.Items[0];

                      //Set Bar code value
                      Image img;
                      string barCodeValue = "700";
                      Barcode.ProvisionBarcodeWithValue(item, true, ref barCodeValue, out img);
                      Barcode.SetBarcodePreview(item);
                      item.Update();                    

                     //Print a message
                     Console.WriteLine("Bar code has been Updated!");
                   }
            }

            //Pause
            Console.ReadLine();
        }
    }
}

No comments:

Post a Comment