You are hereBlogs / Niral's blog

Niral's blog


Create a SharePoint Content Type programmatically

Sometimes it is necessary to create a Sharepoint Content Type by code, specially when batch creating content types.  The following code snippet shows how a sharepoint content type can be created in C#.  I have also included some not-so-simple field types like choice and lookup.
using (SPSite p_site = new SPSite(urlToSite))
{
    using (SPWeb p_web = p_site.OpenWeb())
    {
        SPContentType CustomContentType = new
                SPContentType(p_web.AvailableContentTypes["ParentContentType"],
                p_web.ContentTypes, "MyContentType");
 
        // A string Field
        p_web.Fields.Add("NumberColumn", SPFieldType.Number);
        SPFieldLink fLink1 = new SPFieldLink(p_web.Fields["NumberColumn"]);
        CustomContentType.FieldLinks.Add(fLink1);
 
        // A required number field
        p_web.Fields.Add("StringColumn", SPFieldType.Text, true);
        SPFieldLink fLink2 = new SPFieldLink(p_web.Fields["StringColumn"]);
        CustomContentType.FieldLinks.Add(fLink2);
 
        //A Choice Field
        p_web.Fields.Add("ChoiceColumn", SPFieldType.Choice, false);
        SPFieldChoice choicefield = (SPFieldChoice)p_web.Fields["ChoiceColumn"];
        // Add a group to the filed
        choicefield.Group = "MyGroup";
        // Add choices
        choicefield.Choices.Add(string.Empty);
        choicefield.Choices.Add("Yes");
        choicefield.Choices.Add("No");
        // Set the default choice
        choicefield.DefaultValue = string.Empty;
        choicefield.Update();
        SPFieldLink fLink3 = new SPFieldLink(choicefield);
        CustomContentType.FieldLinks.Add(fLink3);
 
        p_web.Fields.Add("LookupColumn", SPFieldType.Lookup, false);
        SPFieldLookup lookupfield = (SPFieldLookup)p_web.Fields["LookupColumn"];
        // Set the remote lookup list
        lookupfield.LookupList = new Guid("guidofremotelist");
        // Set the remote field
        lookupfield.LookupField = "remotefieldname";
        lookupfield.Update();
        SPFieldLink fLink4 = new SPFieldLink(lookupfield);
        CustomContentType.FieldLinks.Add(fLink4);
        
        p_web.ContentTypes.Add(CustomContentType);
        CustomContentType.Update();
    }
}

Sharepoint Delay Activity Timer

Sharepoint Delay Activity is rounded off to the minute interval that is setup for 'job-workflow' property. This is because the job is responsible for waking up the workflow at the specified time. This job is usually set to run every 5 minutes. It is easy to change (increase or decrease) this value.To get the current job interval value:C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\BIN\stsadm -o getproperty -pn job-workflow -url http://siteaddressOr to change it every minuteC:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\BIN\stsadm -o setproperty -pn job-immediate-alerts -url http://siteaddress -pv "every 1 minutes between 0 and 59"Just be careful about this on production server, as it would create extra load if set to 1 minute interval.

Do you love books ?? Maybe this will help you out...

Amazon.com, the store which sells everything - specially highly discounted books. So today I go there to find something romantic to read for a special person on a very special occasion.  I was so in a good mood. And then it happened.  If found a book Fetish Sex: An Erotic Guide for Couples by some called Violet Blue and Thomas Roche (Thomas Roche...  Hmmm...  Sounds familiar) on pre-order.  And somehow I felt amused.  Very amused.  Further clicks reviled that Violet Blue has written many books, all on the same subject.  She seems very talented.  She also has a blog here. This is just nice.  Maybe I will buy this one when it comes out.  I think such a book in the middle of all programming books would really make a statement.  Would be nice, wouldn't it be ?

One Year . . .

It been a year today, since I actually accepted that something really horrible has happened to me.  I guess one week was a long enough time to anything to sink in, no matter how unbelievable it is.  And life would never be the same again. And I must say life is not the same.  Everything is changed.  Every stupid single thing.  I cant believe it, but it has happened none the less. Is life good ??  Yes, at least for the time being.  In fact its Great.  And I guess I would never have to remember this 'anniversary' ever again.

Blast from the Past !!!

I just discovered that 3D Releams open sourced the classic Duke Nukem 3D a few years back. That means windows ports for the old classic !! Damn its looks good !! Being fickle minded, I hardly stick on to one game. But Duke Nukem was and is probably the only game I played for extended period of time (On my old P60 hehehe ). I tried google and wow, I found the home of jduke3d a windows port of the game. The game is completly playable on my Win 2003 laptop. And then I found the Icing on the Cake - A hi-def mod for the game. So now I can play it at full resolution, with sharp hi-res graphics. This was fun. Played for an hour or so, and boy does that bring back old memories. Lets see if I can get enough time to finish the game one more time. To be frank, after playing all new games, duke nukem kinda feels too easy. I guess I am missing the AI of new games. But then Duke Nukem is Duke Nukem.