Monday, July 6, 2009

Create Document Library using Custom Document Library Template

N.B. I've not tested this code and may not be written using the best practice (esply in disposing the objects), grab the locgic and implement you own.

This peace of code is used to create 8 document libraries with in the specified document library using the custom document library template.

The doc library name and descriptions are picked from the respective arrays.

Pre-requisits: The custom document library template need to be presented in the list template gallary of the site collection.

This can be extended to create the doc libraries in all the webs in the given site collection by iterating through all the site.webs.

namespace MigrateDocLibrary
{
using Microsoft.SharePoint;
public static class HelperDocLib
{
public static void CreateDocLibrayUsingCustomTemplate()
{
string siteCollURL = string.Empty;
string customDocLibTemplateName = string.Empty;
string docLibName = string.Empty;
string docLibDesc = string.Empty;
SPList olist = null;

string[] docLibNames = new string[] { "one", "two", "three", "four", "five", "six", "seven", "eight" };
//string[] docLibDescs = new string[] { "oneDesc", "twoDesc", "threeDesc", "fourDesc", "fiveDesc", "sixDesc", "sevenDesc", "eightDesc" };

customDocLibTemplateName = "CustomDocTemplate";
siteCollURL = "http://webAppName:2020/siteCollName";
docLibName = "DefaultName";
//docLibDesc = "DefaultDesc";
try
{
using (SPSite osite = new SPSite(siteCollURL))
{
SPWebCollection spWebColl = osite.AllWebs;
//SPWeb oweb = osite.OpenWeb();
foreach (SPWeb oweb in spWebColl)
{
SPListTemplateCollection listTemplateColl = osite.GetCustomListTemplates(oweb);
SPListCollection spListColl = oweb.Lists;
for (int i = 1; i <= 3; i++)
{
docLibName = docLibNames[i];
Guid listGuid = spListColl.Add(docLibName, "", listTemplateColl[customDocLibTemplateName]);
olist = oweb.Lists[listGuid];
olist.OnQuickLaunch = true;
olist.Update();
}
oweb.Dispose();
}
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
//
}
}
}
}

Thursday, July 2, 2009

The blog of the SharePoint Team from Microsoft Consulting Services, UK.

Developing application pages for SharePoint can be challenging. This blog post provides guidance on some methods that I use to make the development process easier.

Application Pages?
When developing applications on the Microsoft Office SharePoint Server 2007 (MOSS) framework, there are several available ways to surface functionality to the user via the user interface (UI). The possibilities include web parts, publishing pages, application pages, custom list and site definitions, InfoPath forms, custom field types, etc. Each has its place, with advantages and disadvantages inherent in each.

When developing pages that need to be accessible from any site in the SharePoint farm, often the best choice is to create Application Pages. Application pages are .aspx pages that reside in the _layouts folder on each web front-end server, and can be accessed from any site within SharePoint by using the /_layouts virtual folder (for example http://Server/SiteCollection/Site/_layouts/MyPage.aspx). The pages are usually used for administration pages to this end, and in some cases this is the only option (for example when adding a custom action to the settings page for a site or a content type, unless hard-coding the link, application pages are the only viable option)

chick here for more...