0

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);

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


                wpm.SaveChanges(wpm.WebParts[1]);
                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.. **

1
  • 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 Feb 7, 2011 at 16:41

1 Answer 1

1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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