Condividi tramite


'Modified' field not getting updated anymore

It has occured that the 'Modified' field would not get updated automatically after a change has been done to a document inside the library. Such a scenario would be the following:
When editing a document without checking it out first, the 'Modified' field does not get updated. If you look at the version history of the document you observe that for every new version the last date/time from when the document was last checked out is displayed.

We have compared the field's schema with the one from a 'working' document library:

Working

 <Field ID="{28cf69c5-fa48-462a-b5cd-27b6f9d2bd5f}" Name="Modified" SourceID="" StaticName="Modified" ColName="tp_Modified" RowOrdinal="0" ReadOnly="TRUE" Type="DateTime" DisplayName="Modified" StorageTZ="TRUE" FromBaseType="TRUE"/>

Non-Working

 <Field ID="{28cf69c5-fa48-462a-b5cd-27b6f9d2bd5f}" Name="Modified" SourceID="" StaticName="Modified" ColName="tp_Modified" RowOrdinal="0" ReadOnly="TRUE" Type="DateTime" DisplayName="Modified" StorageTZ="TRUE" Version="11" Group="_Hidden" Hidden="TRUE"/>

So we implemented the following workaround code:

 static void Main(string[] args) {
  using (SPSite ms = new SPSite("https://testserver"))
  using (SPWeb mw = ms.OpenWeb()) {
    try {
      SPList ml = mw.Lists["Test_List"];
      SPField mf = ml.Fields[new Guid("28cf69c5-fa48-462a-b5cd-27b6f9d2bd5f")];
      if (mf.FromBaseType != true) {
        XmlTextReader xr = new XmlTextReader(new StringReader(mf.SchemaXml));
        XmlDocument xd = new XmlDocument();
        XmlNode xn = xd.ReadNode(xr);
        if (xn.Attributes["FromBaseType"] == null) {
          XmlAttribute xa = xd.CreateAttribute("FromBaseType");
          xn.Attributes.Append(xa);
        }
        xn.Attributes["FromBaseType"].Value = "TRUE";
        mf.SchemaXml = xn.OuterXml;
        mf.Update();
      } }
    catch (Exception ex) {
      Console.WriteLine(ex.ToString());
    } } }