Tuesday, September 23, 2008

Programatically Accessing Report Folders & their Report in C#

This post is for accessing Report folder names and correspoinding reports(.rdl files) in Reporting Serbices via C# code.

1. Add a web Reference of the url http:///ReportServer/ReportService.asmx
Name it as ReportingService2005 (my convention)
2. import
using ReportingService2005;
3.

ReportingService2005.ReportingService rs;

rs = new ReportingService2005.ReportingService();
rs.Credentials = new System.Net.NetworkCredential("", "", "");
CatalogItem[] items = rs.ListChildren("/", false);
foreach (CatalogItem item in items)
{
CatalogItem[] items_rdl = rs.ListChildren("/"+item.Name, false);
foreach (CatalogItem i in items_rdl){
i.Name.ToString()
}
}

Note :
First foreach would display all report foldernames.
Second foreach would display all rdl files in first step forders.

Monday, September 22, 2008

Programatically Passing Parameter to Reporting Service in C#

using System.Collections.Generic;


ReportViewer1.ShowCredentialPrompts = false;
ReportViewer1.ServerReport.ReportServerCredentials = new ReportCredentials("username", "MyPassword", "domain");
ReportViewer1.ServerReport.ReportServerUrl = new Uri("http://testuser/Reportserver");
ReportViewer1.ServerReport.ReportPath = "/Report Project State/Report1";
List parameters = new List();
parameters.Add(new ReportParameter("state", DropDownListStates.SelectedItem.Text));
ReportViewer1.ServerReport.SetParameters(parameters);
ReportViewer1.ProcessingMode = ProcessingMode.Remote;
ReportViewer1.ShowParameterPrompts = false;
ReportViewer1.ShowPromptAreaButton = false;
ReportViewer1.ServerReport.Refresh();

Wednesday, September 10, 2008

Deploy a webpart as a feature

Preparing a WSP to Deploy a webpart as a feature

http://sanmuki.blogspot.com/2008/03/preparing-wsp-to-deploy-webpart-as.html

User roles and permissions in SharePoint

Development in C# with User roles and permissions in SharePoint Object Model:
I'll create a SharePoint group using the Object Model, add few users in that group - which will be single users as well as the whole AD groups, create a folder inside the existing SharePoint Document library, break it's permissions inheritance to the parent Document Library, and create new permissions model adding to a single user full rights and to newly created SharePoint group read only rights. On the end, I'll check permissions for any given user if (s)he has rights to do the ceratain operations on the folder items (read, add, edit...).

string groupName1 = "TestGroup1";
SPUser ownerUser = m_SharePointWeb.SiteUsers["mis\\sendil"];

//Add the group to the SPWeb webm_SharePointWeb.SiteGroups.Add(groupName1, ownerUser, ownerUser, "Test group");

//Associate the group to the SPWebm_SharePointWeb.AssociatedGroups.Add(m_SharePointWeb.SiteGroups[groupName1]);


//add some more users and AD groups to this SP Group
m_SharePointWeb.SiteGroups[groupName1].AddUser("mis\\user1", user1@mis.com, "User 1", "User 1 from Management");
m_SharePointWeb.SiteGroups[groupName1].AddUser("mis\\user2", user2@mis.com, "User 2", "User 2 from Sales");
m_SharePointWeb.SiteGroups[groupName1].AddUser("mis\\user3", user3@mis.com,, "User 3", "User 3 from backoffice");

m_SharePointWeb.SiteGroups[groupName1].AddUser("mis\\development", "devgroup@mis.de", "Development", "The whole development AD Group");
//update groupsm_SharePointWeb.SiteGroups[groupName1].Update();

//update webm_SharePointWeb.Update();


To delete the group:

m_SharePointWeb.SiteGroups.Remove(groupName1);m_SharePointWeb.Update();


Give permissions for groups and users to a SharePoint entity (SPWeb, SPList, SPListItem...)

In this example, I'll create a folder inside the existing SharePoint library, break permissions inheritance on the folder level and give rights to one user and one SPGroup to this folder:

//get the existing document librarySPListCollection docLibs = m_SharePointWeb.GetListsOfType(SPBaseType.DocumentLibrary);SPDocumentLibrary DocLib = (SPDocumentLibrary)(docLibs["DocLibraryName"]);
//create folderSPFolder folderTest2 = createDocumentLibraryFolder(DocLib.RootFolder, "TestFolder");
//break role inheritancefolderTest2.Item.BreakRoleInheritance(false);
//folder updatefolderTest2.Update();
//now, give FULL PERMISSIONS permissions to User1SPRoleDefinition role = m_SharePointWeb.RoleDefinitions["Full Control"];SPRoleAssignment roleAssignment;SPUser oneUser = m_SharePointWeb.SiteUsers[@"mis\user1"];roleAssignment = new SPRoleAssignment(oneUser);roleAssignment.RoleDefinitionBindings.Add(role);folderTest2.Item.RoleAssignments.Add(roleAssignment);
//and the readonly rights to the existibg SP GroupSPGroup group2 = m_SharePointWeb.SiteGroups["Test group"];SPRoleAssignment group2RoleAssigment = new SPRoleAssignment(group2);SPRoleDefinition groupRoleDefinition = m_SharePointWeb.RoleDefinitions["Read"];group2RoleAssigment.RoleDefinitionBindings.Add(groupRoleDefinition);folderTest2.Item.RoleAssignments.Add(group2RoleAssigment);
//folder updatefolderTest2.Update();
//web updatem_SharePointWeb.Update();
Check if a specific user has a certain permissions on SPItem, SPList or SPWeb objects
//check if the user has permissions to add new item in the folderSPUser userToCheck = m_SharePointWeb.SiteUsers[@"mis\user1"]if (folderItem.DoesUserHavePermissions(userToCheck, SPBasePermissions.AddListItems)){ Trace.WriteLine("User has permissions to add list items!!!");}else{ Trace.WriteLine("User DOES NOT HAVE permissions to add list items!!!");}
MOSS: To remove "My Settings" and "Personalize this page" menu items from the "Welcome" menu

You will sometimes want to hide certain menu items from the "Welcome" menu in the SharePoint site.
You can do the following:
1. Go to the following folder at the MOSS server:C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\CONTROLTEMPLATES
2. Open file Welcome.ascx in the editor
3. There are more elements. For all those you don't want to display to the users, add the attribute:Visible="False"
For example:
" Description="<%$Resources:wss,personalactions_personalinformationdescription%>" MenuGroupId="100" Sequence="100" ImageUrl="/_layouts/images/menuprofile.gif" UseShortId="true" Visible="False" />
This will hide "MySettings" menu.
WARNING: this is shared file on the Farm-level, so it means, if you do this, the items will not be visible at any SP site on your farm.
And, yes, of course, on the similar way you can add custom menu items under welcome. Just use the attribute
ClientOnClickNavigateUrl="BLOCKED SCRIPT..."
You can define JavaScript function to jump to the custom page or just use Window.Location() to write destination inline.