SharePoint Modified field gone crazy or it just won’t work :)

The problem is very simple in this case. The modified field does not work anymore. When a document or any list item is modified the time stamp does not get updated as it should.

To fix this problem you need to do two things unfortunately.

  1. First you need to update the out of the box Modified field. You can do this by a manually modified URL to the edit page of fields. You have to do this because the field is visible by default. Below is a sample URL:

http://vsp2007dev:24327/_layouts/fldedit.aspx?field=Modified

Pay attention to the bold part of the URL.Just past the bold part after your application domain name and you will be fine. Next all you need is to simply press the “OK” button and be sure to leave everything else unchanged. Especially the update option must be set to yes. What this will do is simply go through every “Modified” field use in your SharePoint application and makes some updates to the field. This will fix the time stamp problem.

2. After you do the seconds step you will run into another problem that an xml attribute from the Modified field schema is missing. This needs to be fixed by a script. Below you will find the code that fixes this error AND also does the update procedure in step 1 described above. So no manual labor here :).

using System;

using System.Collections.Generic;

using System.Text;

using Microsoft.SharePoint;

using System.Xml;

using System.IO;

 

namespace ModifiedFieldFix

{

    public class Program

    {

        static void Main(string[] args)

        {

            StringBuilder output = new StringBuilder();

            TextWriter tw = new StreamWriter(“LOGFILE_” + DateTime.Now.ToFileTime()  + “.txt”);

            if (args != null && args.Length > 0)

            {

                tw.WriteLine(“Given param: ” + args[0]);

                try

                {

                    using (SPSite msite = new SPSite(args[0]))

                    {

                        tw.WriteLine(“Site opened”);

                        SPField siteMField = msite.RootWeb.Fields[new Guid(“28cf69c5-fa48-462a-b5cd-27b6f9d2bd5f”)];

                        siteMField.Update(true);

                        tw.WriteLine(“Modified field update request performed”);

                        foreach (SPWeb mweb in msite.AllWebs)

                        {

                            tw.WriteLine(“———————————————————————-“);

                            tw.WriteLine(String.Empty);

                            tw.WriteLine(“WEB UNDER PROCESSING: ” + mweb.Title);

                            tw.WriteLine(“WEB URL: ” + mweb.Url);

                            for (int i = 0; i < mweb.Lists.Count; i++)

                            {

                                try

                                {

                                    SPList mlist = mweb.Lists[i];

                                    SPField mfield = mlist.Fields[new Guid(“28cf69c5-fa48-462a-b5cd-27b6f9d2bd5f”)];

                                    tw.WriteLine(String.Empty);

                                    tw.WriteLine(“START OF LIST PROCESSING”);

                                    tw.WriteLine(“######################################################”);

                                    tw.WriteLine(“List Title: ” + mlist.Title + ” Field Title: ” + mfield.Title + ” FormBaseType ” + mfield.FromBaseType);

                                    tw.WriteLine(“List location:” + mweb.Url + “/” + mlist.RootFolder.Url);

 

                                    if (mfield.FromBaseType != true)

                                    {

                                        XmlTextReader xmlReader = new XmlTextReader(new StringReader(mfield.SchemaXml));

 

                                        XmlDocument xmlDocument = new XmlDocument();

 

                                        XmlNode xmlNode = xmlDocument.ReadNode(xmlReader);

 

                                        //xmlNode.Attributes[“Hidden”].Value = “FALSE”;

 

                                        XmlAttribute fromBaseType = xmlDocument.CreateAttribute(“FromBaseType”);

 

                                        fromBaseType.Value = “TRUE”;

 

                                        xmlNode.Attributes.Append(fromBaseType);

 

                                        tw.WriteLine(xmlNode.OuterXml);

 

                                        mfield.SchemaXml = xmlNode.OuterXml;

 

                                        mfield.Update();

                                    }

                                    tw.WriteLine(“######################################################”);

                                    tw.WriteLine(“END OF LIST PROCESSING”);

                                    tw.WriteLine(String.Empty);

                                }

                                catch (Exception ex)

                                {

                                    tw.WriteLine(“Error in list procesing of the MODIFIED FIELD FIX!!”);

                                    tw.WriteLine(ex.Message);

                                    tw.WriteLine(ex.StackTrace);

                                }

                                finally

                                {

                                    if (mweb != null)

                                        mweb.Dispose();

                                }

                            }

                            tw.WriteLine(“———————————————————————-“);

                            tw.Flush();

                        }

 

                    }

                }

                catch (Exception ex)

                {

                    tw.WriteLine(ex.Message);

                    tw.WriteLine(ex.StackTrace);

                }

                tw.WriteLine(output.ToString());

                tw.WriteLine(“END OF PROGRAM”);

                tw.Flush();

                tw.Close();

                Console.Write(output.ToString());

            }

        }

    }

}

Advertisements

3 thoughts on “SharePoint Modified field gone crazy or it just won’t work :)

  1. Hello lionardi,

    I have updated “Modified” column in Site Column Gallery as you posted in point 1. Previously my “Modified” disappeared somehow from a views in SharePoint’s libraries.

    Right now I can display the “Modified” field but the field is not updating time stamp value after item modification (only if I use Check Out function in a library).

    I have checked “Modified” column in SharePoint Manager and there is FormBaseType=”FALSE” value. I think There should be a “TRUE” value, but it can’t be modified in SharePoint Manager.

    So maybe your script can help me (point 2) >> but I do not know where I need to put it. Could you please tell me that?

    Marek

    • Hmm, its been a long time since I had to think about this problem but I’ll give it a try. The code in this post should do the trick. It should update in very library and list the modified field formbasetype from false to true. What you need to do is to create a new console application, reference SharePoint DLLs and just compile and run it. But notice that the code in the post will affect all libraries and lists in your site.

      So just compiling and running the code should do the trick. also notice that this might mess up things in worse case scenario. IT is modifying a central field in SharePoint, so take care, backup your content database etc.

    • Also notice that you have to specify as the first parameter to the application the site URL of your sharepoint site. The root preferably. If you just want it to a single site then you would have to modify the code a bit.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s