Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.. **

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
add comment

1 Answer 1

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
add comment

Your Answer

 
discard

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.