0

I am trying to add Link to Item to existing SPView in SharePoint 2010. The same view is further used in ListViewWebpart.

I am using below code to add LinkToItem attribute for field 'SpecificGoal'. Code working fine as I could see that attribute being added to xmlDoc.OuterXml. However, ListViewWebpart is not displaying Link to Item.

Is this a valid way to update the view? Any other way to programmatically adding 'LinkToItem'?

Thank you.

string fieldXml = _view.GetViewXml();
fieldXml = CreateLinkToItem(fieldXml);
_view.SetViewXml(fieldXml);
_view.Update();

private string CreateLinkToItem(string fieldXml)
{            
    XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.LoadXml(fieldXml);
    const string xpathSourceNodes = @"//FieldRef[contains(@Name,'SpecificGoal')]";
    XmlNode targetNode = xmlDoc.SelectNodes(xpathSourceNodes)[0];
    if (null != targetNode)
    {
        XmlAttribute newAttribute = xmlDoc.CreateAttribute("LinkToItem");
        newAttribute.Value = "TRUE";

        targetNode.Attributes.Append(newAttribute);
        break;
    }     
    return xmlDoc.OuterXml;
}

1 Answer 1

1

According to the documentation,

Attempts to set this property are ignored if LinkToItemAllowed is not set to Allowed.

So, I would try adding both:

LinkToItem="TRUE"
LinkToItemAllowed="Required"
3
  • Tried this as well. But no luck.
    – Sagar S.
    Jun 1, 2015 at 12:31
  • @SagarS. try with the lower casing: linkToItem="true" (see: social.msdn.microsoft.com/Forums/sharepoint/en-US/…)
    – MdMazzotti
    Jun 1, 2015 at 13:13
  • Thank you again for replying. As you suggested, tried lower case but still not showing link to item. Modified XML is shown properly till method SetViewXML. Once this method is called, again ViewFields are seen without LinkToItem and LinkToItemAllowed attributes. It just removes them.
    – Sagar S.
    Jun 2, 2015 at 4:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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