Hello everyone -
A friend of mine is having some trouble using the browser based method
of assigning roles and I suggested that we do it programmatically just
in case errors were being suppressed by IE. So far I've seen a lot of
code that creates roles but none that assigns the role to a Windows
group. So for example, I've seen code that can build a role called FOO
with tasks A,B,C associated but how can I assign WINDOMAIN\Users to
that role?
Thanks much,
David SeruyangeJust in case anyone else runs into this, it is done with a policy
object - a short snippet of code like this will do the trick:
MyRS.ReportingService tmp = new MyRS.ReportingService();
// below the NetworkCredential class accepts 3 arguments:
// USERNAME, PASSWORD, DOMAIN
// this is to connect to ReportServer so use an admin account
tmp.Credentials = new NetworkCredential("myusername", "mypassword",
"MYDOMAIN");
try{
Role[] roles = tmp.ListRoles();
foreach(Role r in roles){
if(r.Name == "Browser"){
// modify 'r'
bool bInherit;
Policy[] polis = tmp.GetPolicies("/", out bInherit);
Policy[] pcopy = new Policy[polis.Length + 1];
Array.Copy(polis, pcopy, polis.Length);
Policy np = new Policy();
// MAKE THIS USERNAME CORRESPOND WITH A
// DOMAIN ACCOUNT
np.GroupUserName = @."DOMAIN\User";
np.Roles = new Role[]{r};
pcopy[pcopy.Length -1] = np;
// ASSIGN THIS to the FOLDER that contains
// your report off the ROOT "/"
tmp.SetPolicies("/REPORTFOLDER",pcopy);
Console.Write("Policy assignment has been made.");
}
}
}
catch(Exception ex){
Console.WriteLine(ex.ToString());
}|||david.seruyange@.gmail.com wrote:
> group. So for example, I've seen code that can build a role called
> FOO with tasks A,B,C associated but how can I assign WINDOMAIN\Users
> to that role?
David,
look at bryan's blog under http://blogs.msdn.com/bryanke/articles/91726.aspx
You will find a really good example-script
regards
Frank
No comments:
Post a Comment