Site column does not get deleted
I have a Site column which i delete programaticall开发者_如何学Pythony 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
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.
精彩评论