SPUtility.TransferToErrorPage("This is a user friendly error message.");

<script language='javascript'>
function GetControlByTypeAndName(type, name)
{
var controls = document.body.all.tags(type);
for (var i = 0; i < controls.length; i++)
{
var control = controls[i];
if (control.title.toLowerCase() == name.toLowerCase())
return control;
}
return null
}
function SetInputReadOnly(name)
{
var control = GetControlByTypeAndName('input', name);
if (control)
{
control.style.display = 'none';
var label = document.createElement('');
label.innerHTML = control.value;
control.parentElement.insertBefore(label, control);
}
}
function SetSelectReadOnly(name)
{
var control = GetControlByTypeAndName('select', name);
if (control)
{
control.style.display = 'none';
var label = document.createElement('');
label.innerHTML = control.value;
control.parentElement.insertBefore(label, control);
}
}
function SetDateReadOnly(name)
{
var control = GetControlByTypeAndName('input', name);
if (control)
{
var parentControl = control.parentElement.parentElement.parentElement.parentElement;
parentControl.style.display = 'none';
var label = document.createElement('');
label.innerHTML = control.value;
parentControl.parentElement.appendChild(label);
}
}
SetInputReadOnly('Author Surname');
SetInputReadOnly('Author First Name');
SetDateReadOnly('Document Date');
SetSelectReadOnly('Type of Document');
</script>
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
SPList list = SPContext.Current.Web.Lists["ListName"];
DateTime today = DateTime.Today;
string expectedFolderPath = string.Format("{0}/{1}", today.Year, today.Month);
string currentRootFolder = Page.Request.QueryString["RootFolder"];
string expectedRootFolder = string.Format("{0}/{1}" , list.RootFolder.ServerRelativeUrl, expectedFolderPath);
if (currentRootFolder != expectedRootFolder)
{
if (!DoesFolderExist(list, expectedFolderPath))
CreateFolder(list, expectedFolderPath);
Page.Response.Redirect(HttpUtility.HtmlEncode(string.Format("{0}/{1}?RootFolder={2}", list.ParentWeb.Url, list.Forms[PAGETYPE.PAGE_NEWFORM].Url, expectedRootFolder)));
}
}
/// <summary>
/// Creates a folder (recursively required).
/// </summary>
/// <param name="list">The SharePoint list</param>
/// <param name="folderPath">Folder structure: eg: 2008/11/Sales</param>
public static void CreateFolder(SPList list, string folderPath)
{
if (list == null)
throw new ApplicationException("List is not specified.");
if (string.IsNullOrEmpty(folderPath))
throw new ApplicationException("Folder Path is not specified.");
string[] hierarchy = folderPath.Split('/');
string currentPath = string.Empty;
foreach (string level in hierarchy)
{
if (!string.IsNullOrEmpty(currentPath))
currentPath += "/";
currentPath += level;
if (!DoesFolderExist(list, currentPath))
{
SPListItem folder = list.Folders.Add(list.RootFolder.ServerRelativeUrl, SPFileSystemObjectType.Folder);
folder["Title"] = currentPath;
folder.Update();
}
}
}
/// <summary>
/// Returns whether a folder exists within a list.
/// </summary>
/// <param name="list">The SharePoint list</param>
/// <param name="folderPath">Folder structure: eg: 2008/11/Sales</param>
/// <returns></returns>
public static bool DoesFolderExist(SPList list, string folderPath)
{
if (list == null)
throw new ApplicationException("List is not specified.");
if (string.IsNullOrEmpty(folderPath))
throw new ApplicationException("Folder Path is not specified.");
SPFolder folder = GetFolder(list, folderPath);
return folder.Exists;
}
/// <summary>
/// Returns a folder from a list. If folder does not exist, the Exist property will be FALSE.
/// </summary>
/// <param name="list">The SharePoint list</param>
/// <param name="folderPath">Folder structure: eg: 2008/11/Sales</param>
/// <returns></returns>
public static SPFolder GetFolder(SPList list, string folderPath)
{
if (list == null)
throw new ApplicationException("List is not specified.");
if (string.IsNullOrEmpty(folderPath))
throw new ApplicationException("Folder Path is not specified.");
return list.ParentWeb.GetFolder(list.RootFolder.Url + "/" + folderPath);
}
public static void CreateFolder(this SPList list, string folderPath)
public static bool DoesFolderExist(this SPList list, string folderPath)
public static SPFolder GetFolder(this SPList list, string folderPath)