Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm using C# code to automatically create a read-only Note column that is a truncated version of an existing Note column.

list.Fields.Add(field.Title + " (truncated)", SPFieldType.Note, false);

At the moment, my new column has the title "OldColumnTitle (truncated)". This is what it shows up as when selecting columns for a View, which is good. Unfortunately, this is also what it shows up as in the view itself, which is bad.

If I leave off the + " (truncated)", there's no way in the Edit View form to tell the two apart.

The Title column does what I want - it has several different variations that show up in the Edit View form as "Title", "Title (linked to item)", "Title (linked to item with edit menu)" etc, but show up in the view itself as just "Title".

How can I replicate this? It's probably just a specific property on an SPField I've missed, but if so... I've missed it.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

The string property you are looking for is SPField.AuthoringInfo. Unfortunately this is a readonly property. But the value of this property is stored in the SchemaXml property of the field. So you can set this value by altering the SchemaXml.

using (SPSite s = new SPSite("http://MyWeb"))
{
  using (SPWeb web = s.OpenWeb())
  {
    SPList l = web.Lists["MyList"];
    SPField f = l.Fields.GetField("MyColumn");

    XmlDocument doc = new XmlDocument();
    doc.LoadXml(f.SchemaXml);
    XmlNode fieldNode = doc.FirstChild;

    XmlAttribute attr = fieldNode.Attributes["AuthoringInfo"];
    if (attr == null)
    {
      attr = doc.CreateAttribute("AuthoringInfo");
      fieldNode.Attributes.Append(attr);
    }
    attr.Value = "(truncated)";

    f.SchemaXml = doc.OuterXml;
    f.Update();
  }
}
share|improve this answer
    
Spot on, thanks :) –  Rawling Feb 16 '12 at 13:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.