Customizing SharePoint OOB Forms

January 29, 2014

With my short time working with SharePoint, I have noticed that when you try to do any item creation of file uploading you always get a generic looking form like this:

What we want to do is move away from the generic form and change it completely. This doesn’t just mean changing the css and javascript that executes, but also controlling the back end (C# code). We want to be able to control everything that happens behind the scenes; control where/when controls get added to the page and what happens to them when the user hits the submit button. This hasn’t been an easy task; we have run into multiple issues along the way.

One issue that we have run into was that we wanted to be able to have any list show up no matter where you were on the site. So if you were at http://rootsite/ you could still access a list that was located in http://rootsite/sites/non-rootsite/. The code below is the way that we found worked for adding controls to the page in any type of form situation (new, edit or display). We found that if the “context.FormContext.FormMode = SPControlMode.New” wasn’t there then controls from a different subsite wouldn’t render.

if (!isNewItem)
	field = item.Fields.GetFieldByInternalName(field.InternalName);

var editControl = field.FieldRenderingControl;
editControl.ID = "fld_" + uniqueid; 
editControl.FieldName = field.InternalName;

//edit mode if id is provided
if (!isNewItem)
{
	editControl.ControlMode = this.IsReadOnly ? SPControlMode.Display : SPControlMode.Edit;
	editControl.ItemId = item.ID;

	var context = SPContext.GetContext(HttpContext.Current, item.ID, list.ID, web);
	editControl.RenderContext = context;
	editControl.ItemContext = context;
}
else
{
	editControl.ControlMode = SPControlMode.New;
	editControl.ItemId = item.ID;

	var context = SPContext.GetContext(HttpContext.Current, item.ID, list.ID, web);
	context.FormContext.FormMode = SPControlMode.New;
	editControl.RenderContext = context;
	editControl.ItemContext = context;
}

editControl.ListId = list.ID;

this.pnlControls.Controls.Add(editControl);

Another issue that we have run into is the way validation is handled. Validation hasn’t been as simple as one would expect.

	if(!this.Page.IsValid)
	{
		var validators = this.Validators; 
	}

Here you will get Required field validators that are showing up as BaseValidators but you will also get BaseFieldControls that have the IsValid property set to false. So you have to account for that. But if there have been any custom validation added to the list, then that validation happens (from what we have seen) only when the SPListItem.Update() is called. If validation fails the update will throw a SPListDataValidationException that you have to catch and deal with at that time. So dealing with the validation has been pretty tricky so far.

These are just some of the problems that have become apparent in our process to completely customize the OOB forms. It has been quite the journey and we have come a long ways. But we still have a long ways to go.

Benefits of SharePoint 2013 for Business to Business (B2B) Document Sharing

January 17, 2014

Many RefineCo customers in the Calgary oil and gas industry share documents with each other or with their vendors. It’s how business gets done.

Documents have historically been shared through email, until the corporate Exchange server complains that the attachment file sizes are getting too large. Then some turn to Dropbox or Box.net for document sharing until the corporate network administrator shuts them down due to the insufficient security features of these tools.

Enter SharePoint 2013.

SharePoint 2013 is an excellent B2B collaboration tool. It allows for the quick creation of a document sharing workspace. SharePoint also comes with many basic document management features such as version control, check-in check-out, and publishing. Additionally, since SharePoint is part of the Microsoft stack, your IT department won’t complain about the out-of-the-box security configuration.

RefineCo has helped many companies with their B2B document sharing needs by leveraging SharePoint 2013, either on premise or in the cloud. Depending on our customer’s requirements, these solutions have varied from both basic and out-of-the-box, to customized and feature-rich.

Call us, we want to listen to your needs.