Sometimes you need to just sit back and think for a second
0 CommentsPublished by Ciaran McAuliffe on Friday, June 30, 2006 at 7:28 AM.
As developers we all know that sometimes you need to just sit back and look at the problem from a hot air balloon. I don't know how many times I have spent hours working trying to fix a problem that was caused by a misspelled word in an xml file (circa. yesterday). Here is a classic moment where it really would have been benifical to think about the action before actually carrying it out, I don't know how many times this exact senario has happened to me!
From Seinfeld - The Cheever Letters
JERRY: So we go back to my apartment..
GEORGE: (Expressing shock) Woah. Whoa! Woah!
JERRY: So, we're, uh, foolin' around there.. you know, it's getting a little passionate.. (Scoots closer to George, to prevent others from hearing) and, uh, she starts with the dirty talking.
GEORGE: (Putting his hands up) Alright, alright, hold on! (Jerry has George's full attention) Time out! Woah, woah! (Scooting in, giddy) What did she say?
JERRY: (Modest) Oh, you know, the usual..
GEORGE: No, I don't know. How do I know the usual?
JERRY: Typical things.
GEORGE: (Picking up the ketchup) What typical? Gimme typical. Gimme some typical.
JERRY: She says, uh.. (Mumbles something inaudible. George, so shocked by what he's just heard, accidentally squeezes the ketchup bottle - ketchup squirts out and files off-screen. George reacts deeply)
GEORGE: (Breathing deeply) That's very dirty. (Jerry nods) That's absolutely filthy.
JERRY: ..And then she starts talking about her panties.
GEORGE: (Yelling out to a waitress) Gonna need some water here!
JERRY: So I said something.
GEORGE: Ok, what did you say?
JERRY: (Defensively) Now, bear in mind, I am just trying to keep up.
GEORGE: Of course.
JERRY: Okay? So, she's taking about her panties, so, uh.. So, I said, "You mean the panties your mother laid out for you?"
GEORGE: (Takes a few seconds to mull this one over. Shooting Jerry a confused look, he repeats it) "The panties your mother laid out for you"? (Jerry nods) What
does that mean?
JERRY: (Throwing up his hands) I don't know! It just popped out.
Formating code for the web
0 CommentsPublished by Ciaran McAuliffe on Thursday, June 29, 2006 at 8:56 AM.
I am putting this here mainly because I can never find the link. This is a great website which will apply css styles to your code so that it will look all Visual Studio like when you post it on your blog or whereever you like to post things, it really is none of my business what you do in your spare time.
What kind of person chooses to work with a piece of technology which is not finished and has limited and not uptodate documentation, me for one, and a couple of million others who probably need their heads examined. Yeah, working with beta technology, I love it, I get a sick pleasure out of putting my arm into this black hole and seeing what it will pull out. Well while working with MOSS 2007 over the last couple of days I pulled out a doosey.
Features are and content types are a great addition to SharePoint v3, but lets say you want to create a content type as a feature with little or no documentation about about parts of the schema, that my friends is a feature all onto itself. Below are some of the content types that are included in the PublishingResources feature which comes out of the box, this what I used for my guide.
<ContentType ID="0x0101000F1C8B9E0EB4BE489F09807B2C53288F"
Name="$Resources:cmscore,contenttype_systemmasterpage_name;"
Description="$Resources:cmscore,contenttype_systemmasterpage_description;"
Group="_Hidden"
Sealed="TRUE"
Version="0">
<FieldRefs>
<FieldRef ID="{9da97a8a-1da5-4a77-98d3-4bc10456e700}" Name="Comments" DisplayName="$Resources:core,Description;"/>
<FieldRef ID="{aea1a4dd-0f19-417d-8721-95a1d28762ab}" Name="PublishingContact"/>
<FieldRef ID="{188ce56c-61e0-4d2a-9d3e-7561390668f7}" Name="PublishingPreviewImage"/>
<FieldRef ID="{7581e709-5d87-42e7-9fe6-698ef5e86dd3}" Name="PublishingHidden"/>
FieldRefs>
ContentType>
<ContentType ID="0x0101000F1C8B9E0EB4BE489F09807B2C53288F0054AD6EF48B9F7B45A142F8173F171BD1"
Name="$Resources:cmscore,contenttype_masterpage_name;"
Description="$Resources:cmscore,contenttype_masterpage_description;"
Group="$Resources:cmscore,group_publishingcontenttypes;"
Sealed="FALSE"
Version="0">
<FieldRefs>
FieldRefs>
<DocumentTemplate TargetName="PublishingMasterTemplate.master" />
ContentType>
There is documentation for most of this except for the id attribute (this is true at the time of writing) which just looks like a big dirty hex value, oh, and there is one other thing, How am I supposed to generate this?, small issue, no biggie.
So I managed to figure it out the good old fashioned way, hacking at it like someone had just told me that if I didn't figure it out I would have to write COBOL for the rest of my life, that is not event funny. I started by writing a few lines of C# which converted a GUID into it's equivalent hex value, that was way off. Then I noticed that all of the ids for the content types in this feature started with 0x010100 and the characters following , on the first sample above, looked like a GUID without brackets or hyphens, turns out I was right. So I created an id using this methodology and it set me up as a inheriting from the Document content type but what I wanted to do was inherit from the Page content type.
I remembered from working with the discussion groups in SharePoint v2, on the database level, that the id for post replies was made up of the original post id followed by a new id for that post, and then a reply to that post would be made up of those two post ids contcatenated followed by a new id for that post, you can see that pattern by now I think. It appeared as if that was what was going on here, it was, but with one slight change, the ids must be seperated by '00', easy right!!
From my experiments here is what I have found:
All ids must inherit (begin with) one of the types in this file ctypeswss.xml which belongs to this feature C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\ctypes Here are two of the more common types:
- 0x01 - An Item Content Type
- 0x0101 - A Document Content Type
All inheriting ids must be seperated by 00
So if you wanted your own custom document content type it's id would be
0x010100BA8858B9015344bd9A6B30F1512A2623
where BA8858B9015344bd9A6B30F1512A2623 is my own unique guid. And if I wanted a to create a content type that would inherit from this id it would have to be
0x010100BA8858B9015344bd9A6B30F1512A262300BC82C01887E347749E1FA371534CB19B
where BC82C01887E347749E1FA371534CB19B is my own unique GUID
There could be some other rules around all of this but I have not found any as of yet. Below are some sample content types that inherit from some existing content types:
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<ContentType ID="YourGuidWithOutBracketsOrHyphens"
Name="SpecialTypeA"
Description="SpecialTypeA"
Group="MySpecialContentTypes"
Version="0">
<FieldRefs>
FieldRefs>
ContentType>
<ContentType ID="0x010100YourGuidWithOutBracketsOrHyphens"
Name="SpecialTypeB"
Description="SpecialTypeB"
Group="MySpecialContentTypes"
Version="0">
<FieldRefs>
FieldRefs>
ContentType>
<ContentType ID="0x010100C568DB52D9D0A14D9B2FDCC96666E9F200YourGuidWithOutBracketsOrHyphens"
Name="SpecialTypeC"
Description="SpecialTypeC"
Group="MySpecialContentTypes"
Version="0">
<FieldRefs>
FieldRefs>
ContentType>
<ContentType ID="0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900YourGuidWithOutBracketsOrHyphens"
Name="SpecialTypeD"
Description="SpecialTypeD"
Group="MySpecialContentTypes"
Version="0">
<FieldRefs>
FieldRefs>
ContentType>
<ContentType ID="0x0100YourGuidWithOutBracketsOrHyphens"
Name="SpecialTypeE"
Description="SpecialTypeE"
Group="MySpecialContentTypes"
Version="0">
<FieldRefs>
FieldRefs>
ContentType>
Elements>
That's so far away, I can't click over there!!
0 CommentsPublished by Ciaran McAuliffe on Thursday, June 15, 2006 at 7:10 AM.
So I am sure you have got one of these requests, "I want to be able to open my Outlook from a link on the website.". It is an undstandable request, as most people are unaware of some of the features that windows has, such as, putting a shortcut on your desktop, or putting that very same shortcut into your quick launch toolbar, or even this crazy one, set it up so that when you minimise it it will go and live beside your clock in the system tray. By the way, here is a great app called TrayIt! that allows you to minimise anything to the system tray.
Anyway, enough of my venting, here is some simple javascript to help you achieve that task. You could just create a new ActiveX object everytime and then call mailfolder.display();, but if you do that it will create a brand new window every time you click on the link, not a new instance, just a whole wack load of new windows. The code in the if statement will open outlook and display it if is either closed or minimised to the system tray. If it is minimised on the taskbar or sitting out of focus behind the browser then the code in the else statement will come into play. The reason the timeout is there is because if the code is minimised on the taskbar or out of focus there does not seem to be away to bring it back into focus, so I just minimise it to the system tray and then bring it back to life after a period of time.
If the Outlook link looks like this BLOCKED SCRIPTopenOutlook, replace BLOCKED SCRIPT with j a v a s c r i p t: (make sure to remove the spaces from this. If I didn't put the spaces in it would say BLOCKED SCRIPT again.). It would appear that my blogging app has a filter that is trying to protect you all. And you thought no one cared about you.
<a href="javascript:openOutlook();">Open Outlooka>
<script type="text/javascript">
var objOutlook = null;
function openOutlook(){
objOutlook = new ActiveXObject("Outlook.Application")
if(objOutlook.ActiveWindow == null)
{
try
{
var namespace = objOutlook.getNameSpace("MAPI");
var mailfolder = namespace.getDefaultFolder(6) ;
mailfolder.display();
}
catch(e)
{}
}
else
{
objOutlook.ActiveWindow.WindowState = 1;
window.setTimeout('openOutlook();', 50);
}
}
script>
So what if he can do that, I bet he doesn't have a clue about Iron Python. Check out the video below.
If you are trying to create a custom column as a feature in MOSS 2007 then the documentation is a bit off, so if you are having problems they may not be your fault. Here is a sample that works for sure. Create a folder under the directory below called MyDescriptionField.
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES
When SharePoint is trying to install a new feature it will look in the folder you have created for a file called Feature.xml, this serves as a description of the feature that you are installing, aswell as pointing to any additional files that make up the feature. So create two files in the folder called Feature.xml and Elements.xml . See the content for each one below. The GUIDs that are used for ids on each file are unique to me, so you should create your own.
Feature.xml
xml version="1.0" encoding="utf-8" ?>
<Feature Id="{957328F8-AC46-4c91-9971-584BA3649A05}"
Title="MySpecialField"
Description="A Field Which is used for stuff."
Scope="Site"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="Elements.xml" />
ElementManifests>
Feature>
Elements.xml
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Field ID="{D0CEF044-7CA8-46d1-85B1-9C8711E691BA}"
Name="MySpecialFieldName"
RowOrdinal="0"
Group="MySpecialGroup"
DisplayName="MySpecialFieldDisplayName"
Type="Text"
Required="TRUE"
/>
Elements>
Finally you can install and activate the feature by using the stsadm tool on the command line, here are the command you will need:
stsadm -o deactivatefeature -id 957328F8-AC46-4c91-9971-584BA3649A05 -url http://mymachinename:25898
stsadm -o uninstallfeature -id 957328F8-AC46-4c91-9971-584BA3649A05 -force
stsadm -o installfeature -filename MyDescriptionField\Feature.xml
stsadm -o activatefeature -filename MyDescriptionField\Feature.xml -url http://mymachinename:25898