Technical Fun

After trying this LINQToSharePoint, I must admit I was a bit carried away in forcing Linq to my SharePoint programming needs.
I had this one very “not so important” ambition of iterating through SPList object within the SPListCollection on a SPWeb object.
Problem popped out, SPListCollection was not implementing IEnumerable, so I could not walk easily using Linq to this collection.
So.. to fulfill my ambition, I created a pseudo-adapter class which looked like this:

public class SPListCollectionAdapter : List<SPList>
{
private SPListCollection _listCol;

public SPListCollectionAdapter(SPListCollection listCol)
{
_listCol = listCol;

Refresh();
}

private void Refresh()
{
this.Clear();

foreach (SPList item in _listCol)
{
this.Add(item);
}
}
}

and shortly after that, I could then satisfy my quaint hunger with this method:

private static void DoMOSSLinq()
{
SPSite site = new SPSite(“http://titanctp2:9000&#8221;);
SPWeb web = site.AllWebs[0];

SPListCollectionAdapter listAdapter = new SPListCollectionAdapter(web.Lists);

var result = from l in listAdapter
select l;

foreach (var i in result)
Console.WriteLine(i.Title);

Console.ReadLine();
}

woohooo!!! I am no longer hungry.

I got an XML document that looks like this.

<AreaList>
<Area id=”1″>
<name>Brave Land</name>
<description>An area where the brave may live forever</description>
</Area>
</AreaList>

Now, if I want to search and fetch the text inside the “name” tag based on a supplied “id”, I can rely faithfully on LINQ.

XDocument doc = XDocument.Load(PATH_TO_XML_DOCUMENT);
var x = from area in doc.Descendants(“Area”)
          where (int)area.Attribute(“id”) == MY_SUPPLIED_ID
          select (string)area.Element(“name”);

and consume it using x.First()

aaah …. how readable, how lovely, Nirvana!!!

I spend half of the day configuring K2[blackpearl] in my dev environment.
Initially I got errors and was unable to start the K2[blackpearl] host service and my workspace emitted errors saying that the target machine actively rejected my connection.

Another panic moment …
but then after I contacted their support team, they simply confirmed that at this moment, K2[blackpearl] got some issues when installed on a hard drive that is not the C:\ drive.

Nice. I had to re-do all of the installation.

Lessons (will be updated as I venture further):

- For now, do not install K2[blackpearl] on drives other than C:\ <-- fixed in SP1

[update #1] after cleaning everything (including databases) and a re-installation, I got a successful K2[blackpearl] installation,… this time with a NON-WORKING K2 Web Designer for SharePoint.. OMG ..

[update #2] I got the K2 Web Designer working after I activate it in K2 Administrator tab on the Central Admin. My fault, my bad, sorry, okay? Now I am struggling to improvise with it.

[update #3] A very kind reader has pointed out that the non-C:\ drive installation is now fixed on SP1, as well as a bunch of other improvements.

As many have had, I applied KB934525 to my company’s MOSS environment.
We had two web front ends, and one clustered database serving everything.
Obviously, we had an error completing the configuration wizard after the upgrade binaries were installed.
It is solved by the famous command line mentioned in Bill Baer‘s blog:

psconfig -cmd upgrade -inplace b2b –force

This command solved our upgrade error on both web front ends.

BUT!!!
A few days afterwards, we noticed something funny was happening inside our very MOSS system.
The usage analysis job WAS NOT RUNNING ON the main web front end!!
AND… Our Windows Sharepoint Web Services (a required service that should run on a FARM) was not running on the main web front end (it said Upgrading), AND that service is in the state of Stopping on the other web front end.
Whoaaa .. how could this be??

Panic was in the air, and after a deep dive into the realm of modern contemplation,
this line of command was executed:

stsadm -o provisionservice -action start -servicetype SPWebService

to actually force the service to start on the main web front end. We also force stop the service on the other front end.
It brought back the services to its desired state. (Running on my main one, and Stopped on the other web front end).

It screwed the home directory of my MOSS web site inside IIS(as it defaulted back to C:\Inetpub\blablabla), but then everything was back to normal once I supplied my original MOSS web site path.

After all the chaos, my usage analysis job was back to normal again.

Have you ever desired to pull the content of your CRM picklist attributes and show it to the world using other presentation method? No? really? why? hhh… so sad.
But for those of you who bears the same desire as mine, here’s a little help.

Remember that oMds is an instance of CRM Metadata web service.

private PicklistAttributeMetadata getPickListValue(string entityName, string pickListAttributeName)
{
AttributeMetadata amd = oMds.RetrieveAttributeMetadata(entityName,pickListAttributeName);
PicklistAttributeMetadata pl = (PicklistAttributeMetadata)amd;
return pl;
}

As you see, that method will return PicklistAttributeMetadata, which containes Options attribute, that you can iterate later, like this:
Assume that you have an entity named “new_suppliers” and a picklist attribute called “new_supplierstype”.

PicklistAttributeMetadata pam = getPickListValue("new_suppliers","new_supplierstype");
foreach (Option o in pam.Options)
{
lstAttribute.Items.Add(o.Description); //i.e: you got a listbox called lstAttribute and decided to bind the picklist to it.
}

Ok? No? eh? Why ..? hhh .. so sad..

Tags: ,

Once upon a time, a narcissist felt the urge to display his assembly version to the crowd.
He had edited the AssemblyInfo.cs’ AssemblyVersion attribute to use 1.0.0.*.
Now, he wanted everyone to see the strange numbers of his assembly version.

He referenced System.Reflection carefully,
He then called these lines solemnly

Assembly asm = Assembly.GetCallingAssembly();
string version = asm.GetName().Version.ToString();

He chuckled in an insane glee, and disappeared, never again seen.
He had reached the Nirvana.

Tags: ,

I wanted to deactivate an entity member and was confused.
Here’s to get you out from the same headache.
Replace ENTITYNAMEHANDLER with your entity’s name.

(note that oCrm is an instance of the Crm Web Service)

SetStateENTITYNAMEHANDLERRequest state = new SetStateENTITYNAMEHANDLERRequest();
state.ENTITYNAMEHANDLERState = ENTITYNAMEHANDLERState.Inactive;
state.ENTITYNAMEHANDLERStatus = 2;
state.EntityId = new Guid(GUID_OF_THE_TARGET_MEMBER);
SetStateENTITYNAMEHANDLERResponse stateSet = (SetStateENTITYNAMEHANDLERResponse)oCrm.Execute(state);

With that, you’re done :), are you? eh? really? huh? …

Tags: ,