Just received some lines of code for my colleague Wouter about setting audience targeting on a web part programmatically. I thought sharing would be useful because there is very little documentation out there...
SPLimitedWebPartManager mgr = webMS.GetLimitedWebPartManager("default.aspx", System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
SPLimitedWebPartCollection col = mgr.WebParts;
webparts[0].AuthorizationFilter = ";;;;" + "ROLE 1" + "," + "ROLE 2";
mgr.SaveChanges(webparts[0]);
In this case the first web part gets the role1 and role2 audiences. Checking the MSDN library it says: "Gets or sets an arbitrary string to determine whether a Web Part is authorized to be added to a page". Hmm can someone explain this a little more?