Saturday, July 19, 2008

Join two SPList

QuickTip: Just saw a blog post by Mark Arned who explains how to join two lists based on an ID column. Mark has created a class which generetes a Join and returns you a List in a form of DataTable. The code can be downloaded from here:

http://code.msdn.microsoft.com/ListDataTable

Sahil Malik also shows you how to perform Joins on two SPList and to represent data in a parent/child format. Check here:

http://blah.winsmarts.com/2007-10-Performing_joins_between_SharePoint_lists.aspx

Monday, July 14, 2008

Hiding Item Level Menu from Edit Control Block

Ok, have tried and tried and couldn't find any solid solution to disable Edit Control Block menu from a specific list. There is HideCustomAction element that can be used to disable custom actions. But this cannot be used to disable ECB menu items because ECB menu items are generetaed by JavaScript function in Core.js. There is a very good article by Liam Cleary on various options for disabling ECB menu items but they are targeted to a complete site and cannot be done for a specific list.

There is a workaround which my colleague and me came up with. But this workaround is if you want to totaly disable ECB menu for a particular list. Actually there are couple of workarounds, but its upto you which one you wanna go with (depending upon the time constraint).

First is create your own custom web part which will list all the items using SPGridView and then you can customize it as per your requirement and place that web part within a PlaceHolderMain of your custom copy of AllItems.aspx page. For this you will have to remove the View from a List Definition. This is a time consuming process and I would recommend this only if you have to do lot of customization to your ListView Webpart on AllItems page.

Second option is to use a different column to disaply Title column of a list. For any list there are three types of Title columns. a) Title b) LinkTitleNoMenu c) LinkTitle

Now it must be clear from the name of these columns , LinkTitle column is the one that is displayed by default. This column has got JavaScript functions in the ListDefinition which brings ECB menu when rendered. LinkTitleNoMenu is the column that will just display a hyperlink to DispForm.aspx to view an item. And finally Title column is the one that will display just the title without any link or ECB menu.

Now you can set any of these columns in a view of either a List Definition or from the user interface. So ,this way you can decide if you want to have a ECB menu for a particular list or not.

Sunday, July 6, 2008

Setting Up SharePoint Project Environment

I have been working on setting up development environment in last two days and have come up with few tips which will definitely make our life easier while developing any sort of SharePoint project. These points are just my thoughts, so if some one has any good ideas then please do leave a comment and I will include in my posts.

I have used two tools and developed some code snippets. I will teach you in my next post on how to create these code snippets for feature.xml, elements.xml, onet.xml or any other xml code that you will need to make your development fast.

The tools that I have used are very familiar STSDEV and Andrew Connel's Project Utility Tool. Now you must have already seen, heard or used these tools. But since both the tools have their drawbacks, so we can use both these tools in sync to suit our needs. You can check above links to know in detail about these tools.

STSDEV: Gives us the flexibility of creating .ddf file, .wsp package, deploying assemblies to GAC, adding SafeControl to web.config on deployment and many build types. But one thing that needs to be done manually in STSDEV is creating folder structure. It does creates a basic RootFiles folder structure for you but if you have to add any more folders which has got a deep tree structure then you have to keep adding it manually. This is where Project Utility Tool plays its role.

Andrew Connel's Project Utility Tool : Also gives us benefit of creating .ddf file, .wsp package and more. But it has its drawbacks of not being able to handle any changes in .ddf file manually and some more stuff that STSDEV gives. So we will use this tool for generating the folder structure in a project that STSDEV has created.

I am not really commenting here on which is a good tool or a bad tool. I am really giving you an idea to utilise best of the outcomes of both tools and increase your efficiency and performance in developing custom SharePoint solutions. We really don't want to waste our time in doing repeated things when developing a SharePoint solution so why not use these beautiful tools which makes our life easier.

And also, I am not saying this is the best way to create and maintain Visual Studio projects for SharePoint solutions. If anybody has got any different idea then please do mention it here and share the knowledge among MOSS geeks :-)

Friday, July 4, 2008

Disabling unrequired Services in Windows 2003

I know this post is not relevant to SharePoint as such but will tell you on how you can improve the server security and performance.

There are around more than 100 services that run on a Windows 2003 Server. Some of these services might be useful and some may not be. So why not disable them rather than letting them chew your server resources. There are five basic service that you can quickly think of disabling. These are listed below:

1. ERSvc - Error Reporting Service (Used for reporting application crashes to Microsoft)

2. HidServ - Human Interface Device Access (Used for other smart devices, which you might not use on a server)

3. IsmServ - Intersite Messaging (Used for sending messages from server to server)

4. ScardSvr - Smart Card Access

5. LMHosts - TCP/IP NetBIOS Helper

Now these services are just the start. There is a list of other services that you can check, if you really need them. TechRepublic gives you such list. You can downlowd it from here.

Hope this might be helpful in some instances. Like you can disable such services on your VPC which you might be using as a development environment.

Tuesday, July 1, 2008

Custom Site Column in an existing OOTB List or ContentType

Today I will explain you on how to add a custom site column to an existing Out of the box (OOTB) List type or a content type. There will be instances during your project life cycle when you will want to provision a column to a particular List type or content type, for example you want to add a new column "Expert Comments" to a Wiki library. And you also want to provision this column to any new Wiki library created hereafter in the existing site.

Now for adding a new site column to custom list, you can add it directly when provisioning custom List Definition you can learn this here. But if you want to add a site column to already provisioned list you need to do it through object model.

Firstly you need to find the system content type for a List. Every list in in SharePoint uses a content type, either system content type or custom content type. You can view the content type hierarchy here. And you can find an associated content type for a system List using following lines of code in a console app:

using (SPSite site = new SPSite("http://devmoss/)"))

{

using (SPWeb web =
site.OpenWeb())

{

//List Content types in a web
foreach (SPContentType ct in web.ContentTypes)
{
Console.WriteLine(ct.Name);
}
Console.WriteLine("-------------------------");

//List Content types in a List
SPList list = web.Lists["Posts"];
foreach (SPContentType ctl in list.ContentTypes)
{
Console.WriteLine(ctl.Name);
}
Console.ReadLine();
}



Now once you know the content type of a List in which you wish to add a
custom column, you can use it add a new SPFieldLink to that SPContentType
object. Below is the sample code:




using (SPSite site = new SPSite("http://devmoss001/)"))
{
using (SPWeb web = site.OpenWeb())
{

try
{
string newColumn= "New Column";

//Construct required content type objects
SPContentType wikiContentType = web.ContentTypes["Wiki Page"];

//Check if the site column already exists
if (!web.Fields.ContainsField(newColumn))
{
//If the site column doesn't exist then create a new column and assign it to custom columns group
popularity = web.Fields.Add(newColumn, SPFieldType.Number, true);
SPFieldNumber fieldNum = (SPFieldNumber)web.Fields[newColumn];
fieldNum.Group = "Custom Columns";
fieldNum.Update(true);
}

if (!string.IsNullOrEmpty(newColumn))
{
//Get the field reference of new site column
SPFieldLink fieldLink = new SPFieldLink(web.Fields[newColumn]);

if (fieldLink != null)
{
try
{


//Add the site column to wiki content type
wikiContentType.FieldLinks.Add(fieldLink);
wikiContentType.Update(true);

}
catch (SPContentTypeSealedException ex)
{
}
catch (SPContentTypeReadOnlyException ctEx)
{
}
}

}

}

catch (SPException ex)
{
//Write to Logger
}


}
}


I hope that will be of some help to you. If you have any questions related to this concept then feel free to write to me.
Dogpile
Powered By Blogger