SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

is there any way by which i can add a specific user or group as target audience of my custom web part programatically ??

i am using

                 SPWeb web = SPContext.Current.Web;
                 SPLimitedWebPartManager wpm=                                              web.GetLimitedWebPartManager("SitePages/UserHomePage.aspx?", PersonalizationScope.Shared);
        web.AllowUnsafeUpdates = true;
                AudienceManager am = new AudienceManager(ServerContext.Current);

                = string.Format("{0};;;;", am.Audiences[1].AudienceID);

                web.AllowUnsafeUpdates = false ;

for setting complied audience to my web part. but my requirement is to add 2-3 specific users or their group as target audience ** here we can not compile audience for these user.. **

share|improve this question
on a side node AllowUnsafeUpdates should always be used inside a try/finally construct, so that if your code breaks the security feature is turned back on – Anders Rask Feb 7 '11 at 16:41

You need to add your own People Picker Webpart to the ToolParts collection of your webpart (see this post for an example).

share|improve this answer

Your Answer


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.