Add URLs to Hyperlinks-List via XML or C#

ListInstance Elements.xml

<Data>
   <Rows>
      <Row>
         <Field Name=”URL”>www.google.de, Google</Field>
      </Row>
   </Rows>
</Data>

Note:

  • Webrelative URLs are not working here, only full or serverrelativ URLs are possible!
  • Don’t forget the space after the comma
  • C# – via Feature EventReceiver

    using (SPWeb web = properties.Feature.Parent as SPWeb)
    
    {
    SPList list = web.Lists["Links"];
    SPListItem newItem = list.Items.Add();
    string name = “Google”;
    string url = “www.google.de”
    newItem["URL"] = url + “, ” + name;
    newItem.Update();
    }
    

    Note:

  • All types of URLs are possible, for example you can set up the URL using web.ServerRelativeUrl.