Today I came across an issue where in I was not able to delete a corrupted lookup column from a list . after doing some research i found a good site with the resolution . source site mentioned at the end of the post.
Please save the List as template or take the backup of the site Before you make any changes.
Create an asp.net page with the code at the bottom of this post and put
it in your layouts directory. By default, this is "C:\Program
Files\Common Files\Microsoft Shared\web server
extensions\12\TEMPLATE\LAYOUTS".
Then, browse the page by going to http://[your_sharepoint_domain]/sitename/_layouts/[whatever_you_called_the_page].aspx
Find the column and remove it.
Then, browse the page by going to http://[your_sharepoint_domain]/sitename/_layouts/[whatever_you_called_the_page].aspx
Find the column and remove it.
<%@ Assembly Name="Microsoft.SharePoint.ApplicationPages,
Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
%>
<%@ Page Language="C#" Inherits="Microsoft.SharePoint.WebControls.LayoutsPageBase"
MasterPageFile="~/_layouts/simple.master" %>
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls"
Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities"
Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<asp:Content ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server">
Delete Column
</asp:Content>
<asp:Content ContentPlaceHolderID="PlaceHolderMain" runat="server">
<script runat="server" language="c#">
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (!IsPostBack)
{
LoadLists();
}
}
private void LoadLists()
{
ListName.DataSource = SPContext.Current.Web.Lists;
ListName.DataTextField = "Title";
ListName.DataValueField = "ID";
ListName.DataBind();
}
protected void ListName_OnSelectIndexChanged(object source, EventArgs e)
{
SPList selectedList = SPContext.Current.Web.Lists[new Guid(ListName.SelectedValue)];
FieldName.DataSource = selectedList.Fields;
FieldName.DataTextField = "Title";
FieldName.DataValueField = "ID";
FieldName.DataBind();
}
protected void Delete(object sender, EventArgs e)
{
try
{
SPList selectedList = SPContext.Current.Web.Lists[new Guid(ListName.SelectedValue)];
SPField selectedField = selectedList.Fields[new Guid(FieldName.SelectedValue)];
selectedField.Delete();
selectedList.Update();
EventMessage.Text = "Column Deleted!";
}
catch (Exception ex)
{
EventMessage.Text = ex.Message;
}
finally
{
LoadLists();
FieldName.Items.Clear();
}
}
</script>
<SharePoint:FormDigest runat="server" />
<table>
<tr><td colspan="2"><asp:Label ID="EventMessage" runat="server" /></td></tr>
<tr>
<td>List Name: </td>
<td>
<asp:DropDownList ID="ListName" OnSelectedIndexChanged="ListName_OnSelectIndexChanged" AutoPostBack="true" runat="server" />
</td>
</tr>
<tr>
<td>Column Name:</td>
<td><asp:DropDownList id="FieldName" runat=server /></td>
</tr>
<tr>
<td></td>
<td><asp:Button ID="Button1" runat=server OnClick="Delete" text="Delete" /></td>
</tr>
</table>
</asp:Content>
<%@ Page Language="C#" Inherits="Microsoft.SharePoint.WebControls.LayoutsPageBase"
MasterPageFile="~/_layouts/simple.master" %>
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls"
Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities"
Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<asp:Content ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server">
Delete Column
</asp:Content>
<asp:Content ContentPlaceHolderID="PlaceHolderMain" runat="server">
<script runat="server" language="c#">
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (!IsPostBack)
{
LoadLists();
}
}
private void LoadLists()
{
ListName.DataSource = SPContext.Current.Web.Lists;
ListName.DataTextField = "Title";
ListName.DataValueField = "ID";
ListName.DataBind();
}
protected void ListName_OnSelectIndexChanged(object source, EventArgs e)
{
SPList selectedList = SPContext.Current.Web.Lists[new Guid(ListName.SelectedValue)];
FieldName.DataSource = selectedList.Fields;
FieldName.DataTextField = "Title";
FieldName.DataValueField = "ID";
FieldName.DataBind();
}
protected void Delete(object sender, EventArgs e)
{
try
{
SPList selectedList = SPContext.Current.Web.Lists[new Guid(ListName.SelectedValue)];
SPField selectedField = selectedList.Fields[new Guid(FieldName.SelectedValue)];
selectedField.Delete();
selectedList.Update();
EventMessage.Text = "Column Deleted!";
}
catch (Exception ex)
{
EventMessage.Text = ex.Message;
}
finally
{
LoadLists();
FieldName.Items.Clear();
}
}
</script>
<SharePoint:FormDigest runat="server" />
<table>
<tr><td colspan="2"><asp:Label ID="EventMessage" runat="server" /></td></tr>
<tr>
<td>List Name: </td>
<td>
<asp:DropDownList ID="ListName" OnSelectedIndexChanged="ListName_OnSelectIndexChanged" AutoPostBack="true" runat="server" />
</td>
</tr>
<tr>
<td>Column Name:</td>
<td><asp:DropDownList id="FieldName" runat=server /></td>
</tr>
<tr>
<td></td>
<td><asp:Button ID="Button1" runat=server OnClick="Delete" text="Delete" /></td>
</tr>
</table>
</asp:Content>
Please check the source for further details : http://densom.blogspot.in/2008/07/removing-corrupt-sharepoint-site-column.html
No comments:
Post a Comment