Retrieving Members of Team – CRM


We can make use of the following function for retrieving the members of a particular team

It takes as parameter instance of a ICrmService(CRM 4.0) or CrmService (CRM 3.0) and the guid of the team and returns an arraylist of of all the members found in the team

public ArrayList GetMembersOfTeam(ICrmService service, String TeamID)
// We want the guid of the system users in the team
ColumnSet cols = new ColumnSet(new String[] { “systemuserid” });
// We need to make use of RetrieveMembersTeamRequest class for that
RetrieveMembersTeamRequest rmtRequest = new RetrieveMembersTeamRequest();
// Converting the string TeamID to guid
Guid headGuid = new Guid(TeamID);

rmtRequest.EntityId = headGuid;
rmtRequest.MemberColumnSet = cols;

RetrieveMembersTeamResponse retrieved = (RetrieveMembersTeamResponse)service.Execute(rmtRequest);

// using generic businessEntity list
List<BusinessEntity> sysResult = retrieved.BusinessEntityCollection.BusinessEntities;

// for CRM 3.0
// BusinessEntity[] sysResult = retrieved.BusinessEntityCollection.BusinessEntities;

ArrayList userGuid = new ArrayList();

foreach (BusinessEntity be in sysResult)
systemuser user = (systemuser)be;
return userGuid;


Calling a webservice from an asp page

Say we have created a simple web service like this

public string Hello(String name) {
return “Hello “+name ;

Now we want to call the web service from inside our asp page,

for this we can make use of the following code

Dim myPostData
Dim name
name=”Mickey Mouse”
myPostData=”name=” & name
Dim xmlhttp
Dim postUrl
postUrl = “http://servername/MyService/Service.asmx/Hello&#8221;
Set xmlhttp = server.Createobject(“MSXML2.XMLHTTP”)
xmlhttp.Open “POST”,postUrl,false
xmlhttp.setRequestHeader “Content-Type”,”application/x-www-form-urlencoded”
xmlhttp.send strWebServideDetails
Response.Write(“<b>This is the message i recieved</b>” +xmlhttp.responseText)



System.Net.WebException the request failed with HTTP status 401: Unauthorized.” Source=”System.Web.Services”


I was gettng this error when trying to call the crm’s webservice from my page

The resolution for this is putting the following code in the web.conig

i.e. enable impersonation and deny anonymous access

<authentication mode=”Windows” />
<identity impersonate=”true”/>
<!–Deny all unauthenticated users–>
<deny users=”?”/>


Programmatically uploading and setting permission to a document in a document library in SharePoint

We can use the following code for uploading a document to document library.

// create a filestream object and open an existing file for reading its contents

FileStream oFileStream = File.OpenRead(@”C:\G.doc”);

byte[] content = new byte[oFileStream.Length];

// store the contents in a byte array

oFileStream.Read(content, 0, (int)oFileStream.Length);


// create an SPSIte object

using (SPSite objSite = new SPSite(“http://d-1246&#8221;))


// get reference to the web application or web site

using (SPWeb objWeb = objSite.OpenWeb())


// get reference to the document library. Proposal – name of the document library

SPFolder mylibrary = objWeb.Folders[“Proposal”];

objWeb.AllowUnsafeUpdates = true;

// add the file to the document library and update it

SPFile myFile = mylibrary.Files.Add(“MyProposal.doc”, content, true);


// get the reference to the file just uploaded as a SPListItem for setting permissions

SPListItem myListItem = myFile.Item;

// HasUniqueRoleAssignments – returns false if it inherits permission from parent else true


// BreakRoleInheritance – breaking role inheritance so that we can define our own permissions


// webroledefinitions – Full Right, Design, Contribute and Read

SPRoleDefinitionCollection webroledefinitions = objWeb.RoleDefinitions;

// group – different groups created in that site

SPGroup group = objWeb.SiteGroups[“MyGroup”];

SPRoleAssignment roleassignment = new SPRoleAssignment(group);



// same for the user as well

SPUser user = objWeb.SiteUsers[@”domainname\username”];

SPRoleAssignment roleassignment1 = new SPRoleAssignment(user);

roleassignment1.RoleDefinitionBindings.Add(webroledefinitions[“Full Control”]);





Delete a SSP (Shared Service Provider)

To delete a SSP we need to do the following in the cmd prompt

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN> stsadm -o deletessp -title “shared service name” -deletedatabases

For deleting default ssp first we need to delete all the web application associated with it or associate them with some other shared services !!

CRM 4.0 – Exception: Unhandled Exception: System.Net.WebException: The request failed with HTTP status 401: Unauthorized.


I was facing this error when i was writing a plugin that was using CrmService.

After searching on internet i found out this

The problem was because Friendly name and Organization name were different.

The solution for it was

1. Launch Deployment Manager on the Web server
2. Select the Organization, Right Click -> Disable
3. RightClick Again and Click Edit Organization
4. Change the Organization Name and FriendlyName to be the same
5. Click Next and Finish.