Thursday, 3 May 2012

SharePoint 2007: Datasheet view not working 0x80070057

I've only found this problem in SharePoint 2010. When creating site columns through a feature, the site column type User can generate Datasheet view errors later on, if you forget to add the property Type="User" in the field description:

<Field ID="{cfede2eb-9f3b-4a6b-8bce-9880d2ea34fc}" SourceID="http://schemas.microsoft.com/sharepoint/v3" Name="FieldUserName" StaticName="FieldUserName" DisplayName="FieldUserName" Group="Field group" BaseType="Text" />

You should have done it like this:

<Field ID="{cfede2eb-9f3b-4a6b-8bce-9880d2ea34fc}" SourceID="http://schemas.microsoft.com/sharepoint/v3" Name="FieldUserName" StaticName="FieldUserName" DisplayName="FieldUserName" Group="Field group" BaseType="Text" Type="User" />

But now that you have deployed it live, the best way so data is not lost, is to correct this programmatically with a script:

static void Main(string[] args) {
string url = args[0];
SPSite site = new SPSite(url);

SPWeb web = site.OpenWeb();

List<SPField> fieldsList = new List<SPField>();

fieldsList.Add( web.Fields[new Guid("{cfede2eb-9f3b-4a6b-8bce-9880d2ea34fc}")] );

//you can add other User type fields where you have forgotten it. 

foreach (SPField field in fieldsList) {

Console.Out.WriteLine("Initial value: " + field.SchemaXml);

if (!field.SchemaXml.Contains("List="))

{

field.SchemaXml = field.SchemaXml.Replace("<Field", "<Field List=\"UserInfo\" ");

field.PushChangesToLists = true;

field.Update();

}
}


Good luck!

No comments: