none
SP2010 Custom Barcode Provider

Answers

  • I found the solution for myself.
    Here the source code
     
    using System;
    using System.Collections.Generic;
    using Microsoft.Office.RecordsManagement.PolicyFeatures;
    using System.Text;
    using System.Drawing;
    
    namespace PLA.SP.Core.Barcode {
    
      /// <summary>
      /// This Class contains the Custom Barcode Provider for Code 128B Codes <br/>  /// </summary>
      public class PlanzerBarcodeGenerator : IBarcodeGenerator {
    
        private int _barWeight = 2;
        /// <summary>
        /// Get or Set the Weight of the Barcode Bar
        /// </summary>
        public int BarWeight {
          get { return _barWeight; }
          set { _barWeight = value; }
        }
    
        /// <summary>
        /// Draws a Code 128B Barcode 
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        private System.Drawing.Image DrawBarcodeImage(string id) {
          return Code128.MakeBarcodeImage(id, BarWeight, true);
        }
    
        /// <summary>
        /// Gets the document id to create barcode
        /// </summary>
        /// <param name="spListItem"></param>
        /// <returns>The document Id of current splistitem</returns>
        private string GetDocumentID(Microsoft.SharePoint.SPListItem spListItem) {
          if (spListItem.Properties.ContainsKey("_dlc_DocId"))
            return spListItem.Properties["_dlc_DocId"].ToString();
          else
            return "_dlc_DocID_NotFound!";
        }
    
        #region IBarcodeGenerator
    
        System.Drawing.Image IBarcodeGenerator.GetBarcodeImage(Microsoft.SharePoint.SPListItem spListItem, ref string strValue) {
          return DrawBarcodeImage(strValue);
        }
    
        void IBarcodeGenerator.GetBarcodeValueAndImage(Microsoft.SharePoint.SPListItem spListItem, out string strValue, out System.Drawing.Image imBarcode) {
          strValue = GetDocumentID(spListItem);
          imBarcode = DrawBarcodeImage(strValue);
        }
    
        System.Drawing.Image IBarcodeGenerator.GetSampleBarcodeImage(Microsoft.SharePoint.SPSite spSite) {
          return DrawBarcodeImage("TEST-12-3");
        }
    
        #endregion
      }
    }
    
    For Activating / Deactivating in a Feature
    /// <summary>
        /// Provides the Provider Manifest to activate it
        /// </summary>
        const string sBarcodeProviderManifest = "<PolicyResource id=\"PLA.SP.Core.Barcode.PlanzerBarcodeGenerator\" " +
          "featureId=\"Microsoft.Office.RecordsManagement.PolicyFeatures.Barcode\" " +
          "type=\"Microsoft.Office.RecordsManagement.PolicyFeatures.Barcode.Generator\" " +
          //"visible=\"true\" " + 
          " xmlns=\"urn:schemas-microsoft-com:office:server:policy\" >" +
          "<Name>Planzer Code 128B Provider</Name> " +
          "<Description>This is the Planzer 128B Barcode Provider. Default to all Planzer Group Systems</Description> " +
          "<Publisher>planzer group</Publisher> " +
          "<AssemblyName>PLA.SP.Core.RegisterBarcodeProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=aa3f56284809e565</AssemblyName> " +
          "<ClassName>PLA.SP.Core.Barcode.PlanzerBarcodeGenerator</ClassName>" +
          "</PolicyResource>";
    
    
        /// <summary>
        /// Activates the Barcode 128B for the Planzer Internet Site
        /// </summary>
        /// <param name="properties"></param>
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
          PolicyResourceCollection.Add(sBarcodeProviderManifest);
        }
    
    
        /// <summary>
        /// Deactivates the Barcode 128B feature
        /// </summary>
        /// <param name="properties"></param>
        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
          PolicyResourceCollection.Delete("PLA.SP.Core.Barcode.PlanzerBarcodeGenerator");
        }
    
    In this Project I used GenCode128 to provide the barcode. I hope this solution will help others with the same problem.

    Regards Michael
    • Marked as answer by mdamm-planzer Friday, July 15, 2011 5:23 AM
    Friday, July 15, 2011 5:23 AM