locked
How to remove barcode from list items RRS feed

  • Question

  • Hi !

    I enabled Barcoding on one of the list in Sharepoint by going to Settings> Information Management Policy Settings > .. . There were already some list items in the list and as soon as I enabled barcoding, unique barcodes were assigned to each list item.

    Now the other team doesn't want barcodes.. for now. So I disabled barcoding back. I thought disabling barcode would remove the 2 fields Barcode and Barcode Value from the list. But I still see Barcode field when I open a list item. The items still have a barcode and I cannot find a way to delete it. I checked out Content types - both barcode feilds does not show up, but when I open views I still have an option to include it in view and it still appears in list items.

    How do I get rid of Barcode completely ? There are about 200 list items with barcodes now, how do I remove it from everywhere ?

    Thanks !

    Tuesday, October 18, 2011 7:18 PM

Answers

  • Hi,

    I have developed this code for you so that you can use it in all such situations

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.SharePoint;
    
    namespace DeleteBarcodeIRMPolicyColumns
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("This tool will remove barcode related columns from your list. Before executing this tool make sure that you have removed the policy otherwise it will take you to some other issues ");
                Console.WriteLine("Please enter your site url");
                String siteUrl = Console.ReadLine();
                Console.WriteLine("Please enter your List Name");
                String listName = Console.ReadLine();
                try
                {
                    using (SPSite site = new SPSite(siteUrl))
                    {
    
                        using (SPWeb web = site.OpenWeb())
                        {
                            web.AllowUnsafeUpdates = true;
                            SPList listSource = web.Lists[listName];
                            String[] columnNames = { "Barcode", "Barcode Value", "Exempt from Policy" };
                            for (int i = 0; i < columnNames.Length; i++)
                            {
                                SPField fieldtoBedeleted = listSource.Fields[columnNames[i]];
                                fieldtoBedeleted.AllowDeletion = true;
                                fieldtoBedeleted.Sealed = false;
    
                                fieldtoBedeleted.Delete();
                                listSource.Update();
                            }
                            web.AllowUnsafeUpdates = false;
                            Console.WriteLine("The columns are deleted successfully");
                            Console.ReadLine();
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Console.ReadLine();
                }
            }
        }
    }
    
    
    I hope this will help you out.


    Thanks, Rahul Rashu
    • Marked as answer by Emir Liu Friday, October 28, 2011 6:40 AM
    Thursday, October 20, 2011 6:44 PM

All replies

  • Hi,

    These are the sealed columns and you can not delete them.

    However as per your requirement just uncheck them under the columns in view settings.


    Thanks, Rahul Rashu
    • Edited by Rashu,Rahul Wednesday, October 19, 2011 5:14 AM More content
    Wednesday, October 19, 2011 5:13 AM
  • Hi pratz09,

    Once you enabled Barcodes on the list, the two columns named Barcode and Barcode Value will always exist, no matter whether you disabled Barcodes policy later or not. But there are two scenarios about the two columns:

    First: The items created before Barcodes disabled can always show values of Barcode and Barcode Value, no matter Barcodes is disabled or not.
    Second: Items created after Barcodes disabled can still have the two columns (Barcode and Barcode Value), but can’t show values.

    So, the simplest way is to hide the two columns of the list from “Modify this View”.

    Hope this helps.

    Thanks,
    Emir

    Wednesday, October 19, 2011 5:19 AM
  • Hi,

    I have found a way to remove them by writing code.

    I tried this in my testing environment and it worked.

    I am sharing this code for you:

            SPSite site = new SPSite("YourSiteUrl");

              SPWeb web = site.OpenWeb();

                web.AllowUnsafeUpdates = true;

                SPList listSource = web.Lists["YourListName"];

                 SPField field1 = listSource.Fields["FieldName"];

                field1.AllowDeletion = true;

                field1.Sealed = false;

     

                field1.Delete();

                listSource.Update();

                web.AllowUnsafeUpdates = false;

     

    I hope this will help you out


    Thanks, Rahul Rashu
    • Proposed as answer by pratz01 Thursday, October 20, 2011 3:47 PM
    Wednesday, October 19, 2011 5:23 AM
  • Hi Rahul,

    Thanks a lot mate ! It's great. I would definitely try out your solution. Thanks again.

    Wednesday, October 19, 2011 7:45 PM
  • Hi Emir,

    Yea, I suspected that. From what I found out, Barcode and Barcode value becomes part of meta data of the list once you enable it. You are right, those are the 2 scenarios I am seeing. For new list items created, there is no Barcode value assigned to them but I still see Barcode field and no value in it.

    I wish if there could be a easier way to just hide it from the user.. I mean, can I just hide Barcode field from "View Item" webpage ? It will be great if I don't have to create another view page and redirect user to it. 

    Thanks a lot !

    Wednesday, October 19, 2011 7:50 PM
  • Hi,

    I have developed this code for you so that you can use it in all such situations

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.SharePoint;
    
    namespace DeleteBarcodeIRMPolicyColumns
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("This tool will remove barcode related columns from your list. Before executing this tool make sure that you have removed the policy otherwise it will take you to some other issues ");
                Console.WriteLine("Please enter your site url");
                String siteUrl = Console.ReadLine();
                Console.WriteLine("Please enter your List Name");
                String listName = Console.ReadLine();
                try
                {
                    using (SPSite site = new SPSite(siteUrl))
                    {
    
                        using (SPWeb web = site.OpenWeb())
                        {
                            web.AllowUnsafeUpdates = true;
                            SPList listSource = web.Lists[listName];
                            String[] columnNames = { "Barcode", "Barcode Value", "Exempt from Policy" };
                            for (int i = 0; i < columnNames.Length; i++)
                            {
                                SPField fieldtoBedeleted = listSource.Fields[columnNames[i]];
                                fieldtoBedeleted.AllowDeletion = true;
                                fieldtoBedeleted.Sealed = false;
    
                                fieldtoBedeleted.Delete();
                                listSource.Update();
                            }
                            web.AllowUnsafeUpdates = false;
                            Console.WriteLine("The columns are deleted successfully");
                            Console.ReadLine();
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Console.ReadLine();
                }
            }
        }
    }
    
    
    I hope this will help you out.


    Thanks, Rahul Rashu
    • Marked as answer by Emir Liu Friday, October 28, 2011 6:40 AM
    Thursday, October 20, 2011 6:44 PM