Friday, February 27, 2009

Passing list item ID from SharePoint custom context menu item

We had to add a new menu item in the SharePoint ECB menu in one of our form library. We added it using a simple javascript as specified here. We were able to see the newly added menu item in all the SharePoint list items kept in the form library.

The issue was, We had to pass the ID field of the list item as a parameter to a custom .aspx, which we were redirecting while clicking the new menu item. It was required to find, in which item the menu was clicked. After spending some time with this investigation we found its very simple and straight forward.
"currentItemID" was giving the value. We can even retrieve the list item name using "ctx.listName". Here is the code we used

Wednesday, February 25, 2009

Getting the listItems reside inside a SharePoint folder

One of our project's form library was designed with folders due to the 2000 items per view limitation. (Forms submitted in January will be kept inside a folder called "Jan08")
As part of some other requirement we had to access only the items inside a particular folder. Here is the code we found after some time of investigation with the SPQuery object.

try
{
//25/02/2009- FEB Get only the items specific to a folder
SPSite site = new SPSite(
http://mysite:6666/sites/lat);
SPWeb web = site.OpenWeb();
SPList list = web.Lists["DocumentLibrary1"];
SPQuery query = new SPQuery();
SPFolder myFolder = list.RootFolder.SubFolders["MyFolder_001"];
query.Folder = myFolder;
SPListItemCollection folderItems = list.GetItems(query);
foreach (SPListItem item in folderItems)
{
//Do something here with the items belongs to the folder "MyFolder_001"
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}


Hope if it helps for some people.

Saturday, January 31, 2009

The template you have selected is invalid or cannot be found


We were trying to create a site collection using a template uploaded in to Global template gallery using the stsadm command. But while creating the site collection we were getting the following error.

"The template you have selected is invalid or cannot be found"

After some investigation, again this is due to the Publishing feature. We deactivated the "Publishing feature" in the source site. Recreated the template. Uploaded it again using the Stsadm command. Now the site collection got created successfully.

Cannot find or parse web template file

I was trying to create a SharePoint site collection based on a template saved with lot of site level customizations. Site collection templates should be available in global template gallery and it can be added there using the Stsadm commands I tried to add the template in the global template gallery by using the following command

"stsadm -o addtemplate -filename "c:\mysitecollection" -title "Ari Site collection" "

But it was giving the following error

"Cannot find or parse web template file c:\mysitecollection."

It was a simple error to resolve. But was on a bad day and made me to sweat lot. Yes, the think i missed is the extension of the file name . I modified the command like below and it worked :( another bad day.

"stsadm -o addtemplate -filename "c:\mysitecollection.stp" -title "Ari Site collection" "

Cannot debug project with both ASP and unmanaged debugging enabled

"Cannot debug project with both ASP and unmanaged debugging enabled"

The above mentioned error was occurring when we tried to debug an old .net project in VisualStudio2003. Even though the error was pretty clear it was taking a while for us to find this settings under the property pages of the project. :(