Rez's Spot

Technical tips, suggestions and learnings on SharePoint.

SharePoint Custom List Form Error - Input string was not in a correct format

  • Comments 5

I’m not sure why this happens but here is the scenario:

  1. Open SharePoint Designer and create your own edit form following instructions [1] (i.e. copy EditForm.aspx to MyEditForm.aspx)
  2. Apply the MS Hot Fix that allows attachments on custom edit forms [2]
  3. Hit the save button
  4. Quickly browse to that page in a browser (i.e. http://mysharepointsite/lists/mylist/MyEditForm.aspx)
  5. You get an error similar to:
[FormatException: Input string was not in a correct format.] 
System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +7467367 
System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +119 
System.Convert.ToInt32(String value, IFormatProvider provider) +48 
Microsoft.SharePoint.SPListItem.ValueFromSafeArrayObject(Object obj, SPField fld) +785 
Microsoft.SharePoint.SPListItem.GetValue(SPField fld, Int32 columnNumber, Boolean bRaw) +768 
Microsoft.SharePoint.SPListItem.GetValue(String strName, Boolean bThrowException) +111 
Microsoft.SharePoint.SPListItem.GetValue(String strName) +39 
Microsoft.SharePoint.SPListItem.AddOrUpdateItem(Boolean bAdd, Boolean bSystem, Boolean bPreserveItemVersion, Boolean bNoVersion, Boolean bMigration, Boolean bPublish, Boolean bCheckOut, Boolean bCheckin, Guid newGuidOnAdd, Int32& ulID, Object& objAttachmentNames, Object& objAttachmentContents, Boolean suppressAfterEvents) +1228 
Microsoft.SharePoint.SPListItem.UpdateInternal(Boolean bSystem, Boolean bPreserveItemVersion, Guid newGuidOnAdd, Boolean bMigration, Boolean bPublish, Boolean bNoVersion, Boolean bCheckOut, Boolean bCheckin, Boolean suppressAfterEvents) +166

After a few hours of debugging through my code and trying out other people’s ideas [3], it turns out that it doesn’t have anything to do with my code.

What I found was that if you wait a few minutes and browse to the newly created form again, you don’t get the error.  It looks like once you save the file in SharePoint Designer, it takes a few minutes to propagate the page through the content database. If you browse to the page before this propagation is finished, you get the error “Input String was not in a correct format.”.

***Update***

It looks like I was still having this problem even after waiting a few minutes.  I was now getting:

[FormatException: Input string was not in a correct format.]
   System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +7469351
   System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +119
   System.Convert.ToInt32(String value, IFormatProvider provider) +48
   Microsoft.SharePoint.WebControls.ItemHiddenVersion.OnLoad(EventArgs e) +293
   System.Web.UI.Control.LoadRecursive() +50
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

So I started digging around in reflector to see what was going on in that control:

    // Methods
    [SharePointPermission(SecurityAction.Demand, ObjectModel=true)]
    protected override void OnLoad(EventArgs e)
    {
        this.EnsureChildControls();
        base.OnLoad(e);
        if ((((base.ControlMode == SPControlMode.Edit) && (base.ListItem != null)) && this.Page.IsPostBack) && !base.InDesign)
        {
            HtmlInputHidden hidden = (HtmlInputHidden) this.TemplateContainer.FindControl("owshiddenversion");
            if (hidden == null)
            {
                throw new ArgumentException("Corrupted ItemHiddenVersion template.");
            }
            base.ListItem["owshiddenversion"] = hidden.Value;
            Convert.ToInt32(hidden.Value, CultureInfo.InvariantCulture);
        }
    }

I guess the hidden.Value or owshiddenversion is empty or some sort of string.  Now Microsoft actually has an article on this owshiddenversion property [4] where they state:

“Windows SharePoint Services 3.0 uses the owshiddenversion Field (in the Microsoft.SharePoint.SPBuiltInFieldId Class) to detect conflicts. If this field value is not supplied during the update process, the server will overwrite all changes. A client must always supply this field value during the update process, in order to prevent data loss. The field value is the number that the server returned most recently.”

I guess what might be happening is that the page is in some sort of conflict state.  I’m going to try and remove the ItemHiddenVersion SharePoint control that was put in from the hotfix [2] to see what happens next.

***Update***

I removed it (line below) and things seem to be working, let's wait and see.

<SharePoint:ItemHiddenVersion runat="server" ControlMode="Edit"/>

  

[1] http://kalsing.blogspot.com/2006/11/create-custom-list-form-for-sharepoint.html

[2] http://support.microsoft.com/default.aspx/kb/953271

[3] http://social.msdn.microsoft.com/forums/en-US/sharepointdevelopment/thread/ed33bbd4-a396-476e-b04e-88161dfbdac6/

[4] http://msdn.microsoft.com/en-us/library/cc264293.aspx

Leave a Comment
  • Hi Rez!

    Thanks for this post!

    Removing the "<SharePoint:ItemHiddenVersion runat="server" ControlMode="Edit"/>" worked exactly as you said.

    I spent most of the day yesterday trying to figure out why my custom EditForm.aspx wasn't (1) allowing attachments, and (2) after applying the hotfix for 1, getting the 'Format Exeption' error when trying to submit the edits.

    Before i found this i had created a new "attachment" form to allow attachments to a list item but the problem i had was the user was unable to see those attachments when editing my custom EditForm.aspx. Actually they could have seen the attachments but making ANY changes to the list item gave them the Format Exception error.

    Thanks again for your post. it appears to be working for me...now i'll just have to watch it to see what happens, if anything. :)

    Rick King

    http://www.royaline.com

  • This is gold!!:)

    Can this cause problems if two persons actually are editing the same item simultaneously?

  • Great post! I'll subscribe right now wth my feedreader software!

  • Thanks for this - It's been driving me nuts!

  • I had a strange issue recently: Did some minor changes on an edit “custom list form” and it stopped working