views:

21

answers:

1

Hi,

I have a Site column which i delete programatically using the following code. I have already removed all references to the field previously. However, even if there is not error, it goes to fieldtodelete.Delete() and steps through the next line. However, when i check the Site Column collection using SPM2007 or via the UI the site column is still there.

        Dim fieldtodelete As SPField
        Try
            fieldtodelete = site.RootWeb.Fields.GetFieldByInternalName(name)
            'site.RootWeb.Fields.GetFieldByInternalName(name)
            fieldtodelete.Delete()
        Catch ex As Exception

            Console.WriteLine("Field: {0} was not deleted", name)
            Return 0
        End Try

Any ideas on why sharepoint does this? Also, there are 2 fields with the same name, i am not sure if this has a direct effect on this. I want to delete both.

Thanks

+1  A: 

Since there are 2 fields with the same name, their internal names are likely different than the Name. Are you sure the line

fieldtodelete = site.RootWeb.Fields.GetFieldByInternalName(name)

is actually returning a valid SPField? If not, you will need to find the internal names of the fields, which don't necessarily match up to the Names.

EDIT: Since you said that you are getting the fields back, I realized you aren't calling site.RootWeb.Update() after deleting the field. That should fix the issue.

Steve Danner
I actually verified that i get the field. I've tried variations using the ID too. but when i call the delete function, it just doesnt get it deleted.
Kunatz
Ah, check out my edit, that should take care of it.
Steve Danner

related questions