SharePoint provides a number of different development opportunities for creating information worker solutions. Many of these solutions are well known such as custom lists, content types, and workflows. In this post, I'll point out three key areas that are rich in development opportunities, but routinely overlooked by developers.
Enterprise Search Solutions
The Microsoft Office SharePoint Server (MOSS) comes with an enterprise search engine that can crawl, index, and search the entire SharePoint farm. While many developers are familiar with search, few are creating solutions based on the associated API. Search solutions are great for meeting many end-user needs. For example, end users often want to see documents and lists items that are assigned to them. Using a search solution, you could easily and efficiently create a list of such items.
The search API allows you to use either keyword searches or full-text search as queries in your solutions. These queries return results that can be displayed in lists and grids. The following code, for example, creates a web part that shows all documents added to the portal in the last 7 days.
namespace FullTextWebPart
{
public class RecentDocs:System.Web.UI.WebControls.WebParts.WebPart
{
DataGrid docGrid;
Literal message;
const string queryString = "SELECT url, title, author " +
"FROM Scope() " +
"WHERE \"scope\" = 'All Sites' " +
"AND isDocument=1 " +
"AND write >DATEADD(Day,-7,GetGMTDate())";
protected override void CreateChildControls()
{
docGrid = new DataGrid();
docGrid.AutoGenerateColumns = false;
docGrid.BorderWidth = 0;
HyperLinkColumn title = new HyperLinkColumn();
title.HeaderText = "Document Title";
title.DataNavigateUrlField = "URL";
title.DataTextField = "Title";
docGrid.Columns.Add(title);
BoundColumn author = new BoundColumn();
author.HeaderText = "Author";
author.DataField = "Author";
docGrid.Columns.Add(author);
Controls.Add(docGrid);
Label message = new Label();
Controls.Add(message);
}
protected override void OnLoad(EventArgs e)
{
try
{
EnsureChildControls();
FullTextSqlQuery queryObject = new FullTextSqlQuery(SPContext.Current.Site);
queryObject.ResultTypes = ResultType.RelevantResults;
queryObject.EnableStemming = true;
queryObject.TrimDuplicates = true;
queryObject.QueryText = queryString;
ResultTableCollection results = queryObject.Execute();
ResultTable result = results[ResultType.RelevantResults];
if (result.RowCount > 0)
{
DataTable table = new DataTable();
table.Load(result, LoadOption.OverwriteChanges);
docGrid.DataSource = table;
docGrid.DataBind();
}
queryObject.Dispose();
}
catch (Exception x)
{
message.Text = x.Message;
}
}
}
}
Custom Policies
Along with search, MOSS also supports a technology known as "Policies". Policies are a form of list event handler that can be implemented for an individual list. For example, MOSS ships with an expiration policy that allows you to specify some action that you want to take after a document has existed for a certain period of time. This allows you to specify an information policy, for example, that states "all documents are deleted after 3 years". This technology is made even more powerful because it can be applied to individual libraries by the site administrator as opposed to requiring a developer to explicitly associate the policy with a library.
Open XML Formats
OK, this is not strictly a SharePoint technology, but it is very closely related. Open XML formats are the new Office 2007 document formats. These formats are based exclusively on XML. This means that you can create and edit Office documents programmatically through XML. Open XML formats open up a wide variety of solutions like creating Excel spreadsheets from database information, editing Word documents based on library policies, and using SharePoint list data within documents.
All of these solutions utilize the new System.IO.Packaging namespace that allows you to create and edit Office documents through .NET code. As an example, the following code creates a Word document with a name and content input through the command line.
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml;
using System.IO.Packaging;
namespace MakePackage
{
class Program
{
private const string wordSpace = @"http://schemas.openxmlformats.org/wordprocessingml/2006/main";
private const string partType = @"application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml";
private const string partUri = @"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument";
private const string partId = "rId1";
static void Main(string[] args)
{
try
{
using (Package package = Package.Open(
args[0], FileMode.CreateNew, FileAccess.ReadWrite))
{
//Build the document.xml file with text in it
XmlDocument documentXml = new XmlDocument();
XmlElement documentElement = documentXml.CreateElement(
"w:document", wordSpace);
documentXml.AppendChild(documentElement);
XmlElement bodyElement = documentXml.CreateElement(
"w:body", wordSpace);
documentElement.AppendChild(bodyElement);
XmlElement pElement = documentXml.CreateElement("w:p", wordSpace);
bodyElement.AppendChild(pElement);
XmlElement rElement = documentXml.CreateElement("w:r", wordSpace);
pElement.AppendChild(rElement);
XmlElement tElement = documentXml.CreateElement("w:t", wordSpace);
rElement.AppendChild(tElement);
XmlNode tNode = documentXml.CreateNode(
XmlNodeType.Text, "w:t", wordSpace);
tNode.Value = args[1];
tElement.AppendChild(tNode);
//Create the part item for document.xml
Uri Uri = new Uri("/word/document.xml", UriKind.Relative);
PackagePart partDocumentXML = package.CreatePart(Uri, partType);
StreamWriter stream = new
StreamWriter(partDocumentXML.GetStream(
FileMode.Create, FileAccess.Write));
documentXml.Save(stream);
stream.Close();
package.Flush();
//Create relationship for document.xml
package.CreateRelationship(Uri, TargetMode.Internal, partUri, partId);
package.Flush();
package.Close();
}
}
catch (Exception x)
{
Console.WriteLine(x.Message);
}
}
}
}
Scot Hillier is an independent consultant and Microsoft Most Valuable Professional focused on creating solutions for information workers with SharePoint, Office, and related .NET technologies. He is the author of 10 books on Microsoft technologies, including Microsoft SharePoint: Building Office 2007 Solutions in C# 2005. Scot splits his time between consulting on SharePoint projects and training for the Ted Pattison Group. Scot is a former U. S. Navy submarine officer and graduate of the Virginia Military Institute. Scot can be reached at scot@shillier.com.
Win one of 15 free copies of WSS and MOSS 3.0 Development (Video Training): 10 Solutions Every SharePoint Developer Should Know How to Create by Scot Hillier. Click for entry details.
See two free training video excerpts:
Plus, GET FREE CHAPTERS of an entire library of books for Microsoft professionals.
The opinions expressed in this Weblog are those of the writer and may not represent the opinions of Network World.
|
|
Post new comment