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.
  • Getting E-Mail and Attachments in Plug-In using LINQ

    When updating an e-mail entity, only updated metadata is available in InputParameters.
    Here is some code to get the whole entity and attachments using LINQ:

    protected void ExecutePostEMailUpdate(LocalPluginContext localContext)
    {
        if (localContext == null)
    	{
    		throw new ArgumentNullException("localContext");
    	}
    
    	IPluginExecutionContext context = localContext.PluginExecutionContext;
    	IOrganizationService service = localContext.OrganizationService;
    	ITracingService tracingService = localContext.TracingService;
    
    	OrganizationServiceContext serviceContext = new OrganizationServiceContext(service);
    
    	if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
    	{
    		Entity targetEntity = (Entity)context.InputParameters["Target"];
    		if (targetEntity.LogicalName != "email")
    			return;
    
    		try
    		{
    			Email email = targetEntity.ToEntity();
    
    			email = (from mail in serviceContext.CreateQuery()
    				where (mail.Id == email.Id)
    				select mail).FirstOrDefault();
    
    			var attachmentQuery = (from a in serviceContext.CreateQuery()
    				where (a.ObjectId == email.ToEntityReference())
    				select a);
    
    			foreach (var attachment in attachmentQuery)
    			{
    				var fileName = attachment.FileName;
    			}
    		}
    		catch (FaultException e)
    		{
    			throw new InvalidPluginExecutionException(e.ToString());
    		}
    	}
    }