Posts Tagged ‘SharePoint’

Benefits of upgrading to SharePoint 2010

Wednesday, June 2nd, 2010

We’ve been getting a lot of questions about SharePoint 2010 and if and why companies should upgrade from 2007 to 2010.  As with any new product out there, upgrading just for the sake of it is usually not a good idea and does not guarantee ROI.  Having worked with Microsoft directly through the Office 14 Developer Advisory Council, we have some specific insight into some of the key benefits a company can expect to gain by upgrading or migrating to SharePoint 2010.  If any of these appeal to you, you may want to look at making the move to 2010.

 

Enhanced UI - Microsoft has done a great job with the new UI of SharePoint 2010.  Aside from taking advantage of Silverlight and Ajax to create a much richer user experience, MS has also taken advantage of the ever popular ribbon UI and incorporated that into SharePoint 2010.  In general MS is working to converge SharePoint 2010 and Office products so that eventually, you won’t be able to tell where SharePoint stops and Office begins, or visa-versa.  This means less training and greater efficiency for your end users.

 

Empowered Users — SharePoint 2010 was built with the notion that IT cannot deliver all mission critical systems to all departments all of the time. By greatly enhancing and adding to the set of building blocks that users can incorporate into their own pages and workspaces (referred to as Composites in 2010), users can create powerful and practical business applications on their own.  In 2007, anything that was remotely complex would typically require Visual Studio, XML, or SharePoint Designer expert to build something practical.  Non technical users can also take existing solutions such as Access databases and convert them into SharePoint web-based data entry applications so that existing investments are not thrown away in order to become centrally managed.

 

Enterprise Level Social Collaboration - Microsoft has made some great strides in defining collaboration.  They have done a great job of emulating mainstream social collaboration utilities such as Facebook, Wordpress, Wikipedia, etc. and making them ideal for corporate usage.  This makes it much easier for your users to make the leap from traditional back and forth email communication to a social networking centric communication model.  This means, much more efficient communication and the constant capturing of tacit business knowledge without burdening your workforce.

 

Two-way Interaction with Business Data – SharePoint 2010 has reengineered the business data catalog to no longer require complex XML configurations.  Line of business systems can be integrated quickly and easily into SharePoint. Through an interface that is very similar to SharePoint lists, users can edit Line of Business data directly in SharePoint in a secure and efficient manner.  This is a big deal because most end users will only end up using 10-15% of a line of business system but you still have to train them on the overall system.  If they can interact with only the data they need to through a consistent and streamlined interface like SharePoint, the benefits are apparent.

 

Control for IT — Ok, so we have all of this great functionality and users can create their own powerful business applications with minimal involvement of IT.  Although this sounds like a great thing for the customer, this also tends to make most IT departments cringe.  SharePoint 2010 has added several control features that allow for IT to retain control and not let rogue applications and solutions hijack your company resources.  Through a robust throttling mechanism, IT can “Sandbox” end user solutions and only allow them to leverage a certain number SharePoint Server Resources (a Server Resource is a point system comprised of memory, disk space, CPU cycles and several other parameters that you can configure and put weights to).  The nice thing is you can Sandbox a site, page, web part, list, workflow, etc.  This granularity allows for lots of control.

 

On Premise or In the Cloud — SharePoint 2010 also unlocks several compelling deployment scenarios for your organization. With its new architecture, control mechanisms, and scalability features, companies can deploy either on premise or in the cloud without losing functionality or control.  In previous versions, only Windows SharePoint Services could be deployed in the cloud.  The biggest hindrance to MOSS 2007 in the cloud was the Shared Service Provider made MOSS difficult to fit on a shared, hosted environment.  SharePoint 2010 has gotten rid of the SSP and moved to an architecture that is conducive to this.

5 things that you think will work in MOSS 2007 but don’t

Monday, December 7th, 2009

When you work for some time with MOSS 2007, sometimes you might overlook some inconsistencies within the product.  Here is a quick list of quirks(now say that fast!) with MOSS 2007

  1. When you have a Gantt view of the Task List, Web part connections are unavailable.  Hence you cant filter a Gantt View using the Filter Web Parts
  2. DateTime columns cannot be used for Grouping in the Content Query Web Part out of the box
  3. You cannot use the PortalSiteMapProvider to retrieve Navigation items from another site collection
  4. If you have a Date Column in a List, it cannot be used as a Lookup Column on another List
  5. When you use the Content Migration APIs to transfer content from one farm to another, people fields do not migrate accurately

Part 1: Creating and Deploying a Basic SharePoint Web Part

Tuesday, September 15th, 2009

NOTE: This post is a part of the tutorial entitled Building a SharePoint List Aggregator Web Part with Custom Properties.

Creating a SharePoint Web Part

To get started, open VS 2008, click on File > New Project, choose Class Library project template, name your project, choose the location and click OK.

Close the Class1.vb file that was open by default and rename it to something more meaningful, for example ListAggregator.vb. Click Yes in the prompt window to make sure all references are renamed as well. Now open the file again.

First of all, you need to add references to the assemblies that are required for web part development – System.Web and Microsoft.SharePoint.dll. To add references, right-click on References in the Project Explorer and click Add Reference. These assemblies should be under the .NET tab. If you can’t locate Microsoft.SharePoint.dll there, get it from this directory:

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\ISAPI”

Include necessary namespaces and add code, as shown below:

Imports System

Imports System.Text

Imports System.Web

Imports System.Web.UI

Imports System.Web.UI.WebControls

Imports System.Web.UI.WebControls.WebParts

Imports Microsoft.SharePoint

Imports Microsoft.SharePoint.Utilities

Imports Microsoft.SharePoint.WebControls

Imports Microsoft.SharePoint.WebPartPages

Public Class ListAggregator

Inherits System.Web.UI.WebControls.WebParts.WebPart

Protected Overrides Sub CreateChildControls()

MyBase.CreateChildControls()

Controls.Add(New LiteralControl(“Simple Web Part”))

End Sub

End Class

Important things to note here:

  • Since this is a class library, you have to create and configure all page controls in code
  • All the namespaces we will need for this web part are included
  • A web part has to inherit from System.Web.UI.WebControls.WebParts.WebPart class
  • You need to override the CreateChildControls() method and call the base method in order to add content to the web part
  • To add web controls to a web part use Controls.Add method, where Controls is a System.Web.UI.ControlCollection object

Deploying the Web Part

Before you deploy the web part you need to sign it, so that the resulting assembly is strongly named. To do this, select Project > ListAggregator Properties, click on the Signing tab, check Sign the assembly checkbox, and select New from the dropdown. Then choose a file name for the Key and click OK.

Now build the project, locate the ListAggregator.dll in the bin/Debug folder of the project directory and deploy it into the Global Assembly Cache (GAC), which is located at C:\Windows\assembly. To deploy, you need to simply drag-and-drop the file into the GAC directory. If the assembly wasn’t strongly named (signed) then you would get an error here.

Now, that your .dll is in the right place, you need to perform one more step to make this assembly “visible” to SharePoint. You need to add a SafeControl entry in the Web.config file for your SharePoint portal. This file is located in the following folder:

C:\Inetpub\wwwroot\wss\VirtualDirectories\<YourVirtualDirectoryName>

In the Web.config file, locate the closing </SafeControls> tag, and add this line right above it:

<SafeControl Assembly=ListAggregator, Version=1.0.0.0, Culture=neutral, PublicKeyToken=u2v507834d67109b Namespace=ListAggregator TypeName=* Safe=True />

Please replace PublicKeyToken in the code below with the one for your assembly. To find out the strong name for your assembly along with some other useful information, you can use a free tool called .Net Reflector.

Now, you have to add your new web part to the Web Part gallery, which is a collection of all web parts available for use in SharePoint sites. To do this, open your SharePoint site in the browser and navigate to Home > Site Actions > Site Settings > Modify All Site Settings and click on Web Parts link under Galleries. Once there, click on the New button on the toolbar, find your assembly in the list, tick a checkbox next to it, and click the Populate Gallery button. If you can’t locate your assembly on this page, it means SharePoint cannot yet see your assembly, so double check that you performed all of the previous steps correctly.

You can also click on the Edit icon next to your web part and modify the metadata. Adding a distinctive group name will help you locate this web part faster when you add it to a page.

Adding the Web Part to a Web Part Page

Once the web part has been added to the Web Part gallery, it can be used on any of the web sites in this site collection. Just navigate to a page that you want to host this web part, click on Site Actions > Edit Page and click on Add a Web Part button in the desired web part zone. In the pop up window, check your web part and click the Add button. When done, click on Exit Edit Mode link under Site Actions. Your web part should display the text “Simple Web Part” if you completed all the steps correctly.

Continue to Part 2: Adding Custom Properties to a SharePoint Web Part.

Building a SharePoint List Aggregator Web Part with Custom Properties

Tuesday, September 15th, 2009

This is a tutorial on how to build a customizable web part for MOSS 2007 or WSS 3.0.

We will be building a List Aggregator – a web part that can collect, filter, and display list items from all lists of a certain type from all sub-sites in up to 3 site collections. This web part will have the following features:

  • Users will be able to select up to three site collections to aggregate content from
  • Users will be able to choose one of these list types: announcements, calendar events, or tasks
  • Only current announcements and calendar events will be displayed
  • Only tasks that are in “Not Started”, “In Progress”, or “Waiting on Someone Else” will be displayed

This web part is somewhat similar to the out-of-the-box Content Query web part, but Content Query can only aggregate content from a single site collection. On the other hand, List Aggregator will not have the robust filtering that Content Query provides.

First, we will build a basic web part and deploy it. Then, we will add some custom properties to enable users to change web part settings in the UI. At last, we will add functionality to collect list items from multiple SharePoint lists. Hmm, not quite the “Hello World” web part you expected, is it?

To successfully complete this tutorial, make sure you have access to either a physical or virtual development environment that has Windows Server 2003 and either WSS 3.0 or MOSS 2007. Also, make sure it has Visual Studio 2008 installed. We will be using VB.NET.

The rest of this tutorial is broken into three parts, which I will add as they become available. Click on one of the links below to continue:

  1. Creating and Deploying a Basic SharePoint Web Part
  2. Adding Custom Properties to a SharePoint Web Part
  3. Adding CAML Queries to a Web Part to Collect Data from SharePoint Lists

Passing Parameters to a Silverlight Webpart in SharePoint

Friday, July 17th, 2009

In this blog, I will outline the steps necessary to pass initialization parameters to a Silverlight webpart within SharePoint.  Due to the client-side processing nature of Silverlight applications, it is not easy to get server-side information for use in your Silverlight application during runtime.  Fortunately, leveraging the SilverlightApp.InitParameters property makes it quite straight-forward to pass information on startup..

Steps:

  1. Define the SilverlightApp1.InitParameters in the webpart’s CreateChildControls method
  2. Extract these parameters in the Application_Startup method in App.xaml.cs and pass it to the page
  3. Extract the information from the Page parameters

Define the SilverlightApp1.InitParameters in the webpart’s CreateChildControls method

In the CreateChildControls method in the webpart.cs class, we want to create our Silverlight application control and add it to the page.  The Silverlight application object has a property called InitParameters.  This is a string that accepts parameters in this format:  “parameter=value”.  Each parameter/value pair is seperated by a comma, like this:  “parameter1=value1, parameter2=value2″.

Here is a code snippet of the entire Silverlight instantiation, manipulation, and addition:

protected override void CreateChildControls()
{
base.CreateChildControls();

silverlightControl = new System.Web.UI.SilverlightControls.Silverlight();
silverlightControl.ID = "Silverlight App";

silverlightControl.MinimumVersion = "2.0.31005.0";
string parameters = "SiteUrl=" + SPContext.Current.Web.Url.ToString() + ", " +  "Date=" + DateTime.Now.ToString();
silverlightControl.InitParameters = parameters;

silverlightControl.Source = SPContext.Current.Site.Url + "/XAPS/SilverlightApp.xap";

this.Controls.Add(silverlightControl);
}

As you can see, two parameters will be passed to the Silverlight application at startup.  The first is the current site url that the webpart resides in.  This is useful when using SharePoint web services that require the url of the SharePoint site.  It is key that we use the InitParameters property to pass this information, as the Silverlight application runs on the client-side, so accessing the site url within the Silverlight application itself is not possible.  The second is the Date/Time when the application starts up.

Extract these parameters in the AppStartup method in App.xaml.cs

In the Silverlight application in App.xaml.cs, there is a method called Application_Startup with event arguments StartupEventArgs.  These event args have a property called InitParams.  This is the property that is passed to the page when it is instantiated and set as the RootVisual.

private void Application_Startup(object sender, StartupEventArgs e)
{
RootVisual = new Page(e.InitParams);
}

Extract the information from the Page parameters

In Page.xaml.cs, the original initialization parameters are passed as page instantiation parameters as shown above.  Within Page.xaml.cs, the Page creation method takes the e.InitParams object, which is of type IDictionary<String, String>.  Therefore, we extract this information like so.

public Page(IDictionary initParams)
{
string siteUrl = initParams["SiteUrl"];

string dateTimeNow = initParams["Date"];

InitializeComponent();

}

We now have two string values, the current SharePoint site url and the date/time when the application is started that can be used by the Silverlight application.

Using SharePoint Web Services to Integrate SharePoint and Silverlight

Friday, July 17th, 2009

When integrating Silverlight with a SharePoint site, it becomes apparent very early on that using data that lives in SharePoint in your Silverlight application will be difficult.  The reason being that Silverlight applications run on the client-side.  Therefore, a developer wanting to extract list data or use files hosted in SharePoint cannot simply use the SharePoint object model directly to accomplish this.  Fortunately, SharePoint provides out-of-the-box web services that can be leveraged to get this data.

The first step to using the SharePoint web services is creating the HttpWebRequest object and beginning the call.  In this example, we will be using the Lists.asmx web service located at http://sharepointsite.com/_vti_bin/Lists.asmx.  We will define the Method, ContentType, and Headers of the web service.  Finally, we will call the BeginGetRequestStream method to begin the call.

private void GetDataEntryPoint()
{
try
{
string siteUrl = "http://sharepointsite.com"

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(siteUrl + "/_vti_bin/Lists.asmx", UriKind.Absolute));

request.Method = "Post";
request.ContentType = "application/soap+xml; charset=utf-8";
request.Headers["ClientType"] = "Silverlight";
request.BeginGetRequestStream(new AsyncCallback(DataRequestCallback), request);
}
catch (Exception ex) { string error = ex.Message; }
}

In the above snippet, you will see the DataRequestCallback delegate.  This is the method we will work with next.  It will be called whenever we receive the asynchronous callback from SharePoint telling us that we have a connection and it is ready for more information.  In this method, we will do a few things.  We will define the SOAP envelope that contains information that tells SharePoint what data we are looking for.  I’ve included a query option as an example that tells SharePoint to send us any attachments as well for each item.  In the envelope below, the 3 items that need to be changed are the list name, the field to sort with, and the fields we want to be returned.  The next part of this method reacreates the HttpWebRequest object using the asynchronous result.  We also define the encoding type we will want to use.  Next, we see the Stream object body that will temporarily hold the data.  Then we will use our configured encoding to write the response to an array of bytes.  This object will be used by the next callback method to collect the data.  We then define our method delegate, DataResponseCallback, to be called when the data is returned by SharePoint in an asynchronous callback.

private void DataRequestCallback(IAsyncResult asyncResult)
{
try
{
string envelope =
@"&lt;?xml version=""1.0"" encoding=""utf-8""?&gt;
&lt;soap12:Envelope
xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""
xmlns:xsd=""http://www.w3.org/2001/XMLSchema""
xmlns:soap12=""http://www.w3.org/2003/05/soap-envelope""&gt;
&lt;soap12:Body&gt;
&lt;GetListItems xmlns=""http://schemas.microsoft.com/sharepoint/soap/""&gt;
&lt;listName&gt;List Name&lt;/listName&gt;
&lt;query&gt;
&lt;Query xmlns=""""&gt;
&lt;OrderBy&gt;
&lt;FieldRef Name=""Title"" /&gt;
&lt;/OrderBy&gt;
&lt;/Query&gt;
&lt;/query&gt;
&lt;viewFields&gt;
&lt;ViewFields xmlns=""""&gt;
&lt;FieldRef Name='Title' /&gt;
&lt;FieldRef Name='Age' /&gt;
&lt;/ViewFields&gt;
&lt;/viewFields&gt;
&lt;queryOptions&gt;
&lt;QueryOptions xmlns=""""&gt;
&lt;IncludeAttachmentUrls&gt;TRUE&lt;/IncludeAttachmentUrls&gt;
&lt;/QueryOptions&gt;
&lt;/queryOptions&gt;
&lt;/GetListItems&gt;
&lt;/soap12:Body&gt;
&lt;/soap12:Envelope&gt;";

UTF8Encoding encoding = new UTF8Encoding();
HttpWebRequest request = (HttpWebRequest)asyncResult.AsyncState;

Stream body = request.EndGetRequestStream(asyncResult);

byte[] formBytes = encoding.GetBytes(envelope);

body.Write(formBytes, 0, formBytes.Length);
body.Close();

request.BeginGetResponse(new AsyncCallback(DataResponseCallback), request);
}
catch () {}
}

In the next method, we will receive the asynchronous result from SharePoint containing the data we want.  Unforunately, it is not in the correct format for how we want to use it.   We will save this returned data into a string called responseString (this will be defined outside our method so that it can be accessed by multiple methods).  We will then use the Dispatcher to invoke our processing method, ProcessResponseData, that will parse the raw data and load it into a custom object.

private void DataResponseCallback(IAsyncResult asyncResult)
{
HttpWebRequest request = (HttpWebRequest)asyncResult.AsyncState;
HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asyncResult);
Stream content = response.GetResponseStream();

if (request != null &amp;&amp; response != null)
{
if (response.StatusCode == HttpStatusCode.OK)
{
using (StreamReader reader = new StreamReader(content))
{
responseString = reader.ReadToEnd();
reader.Close();
}

try
{

this.Dispatcher.BeginInvoke(ProcessResponseData);

}

catch () {}
}
}
}

Before we jump into the parsing of the raw data SharePoint gave us, let’s define an object called Person that will have properties of Title, Age, and Image.


public class Person
{
private string _image;
public string Image
{
get { return _image; }
set { _image = value; }

}
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}

private string _age;
public string Age
{
get { return _age; }
set { _age= value; }
}
}

Now that we have our custom Person object, we can instantiate one and assign it values using our SharePoint web services data.  For each attribute we are reading, we find it by passing “ows_FieldName” to the MoveToAttribute method of the XmlReader object.  For the URL of the attachment, we need to use some simple Regex.Replace to extract the actual URL.  This technique can be used for any attachments.  Here is a code snippet:


private void ProcessResponseBusinessUnitListItems()
{
try
{
using (XmlReader reader = XmlReader.Create(new StringReader(responseString)))
{
while (reader.Read())
{
if (reader.IsStartElement("row", "#RowsetSchema"))
{

reader.MoveToAttribute("ows_Title");
string titleString = reader.Value;

reader.MoveToAttribute("ows_Name");
string nameString = reader.Value;

reader.MoveToAttribute("ows_Age");
string ageString = reader.Value;

reader.MoveToAttribute("ows_Attachments");
string attachmentUrl1 = reader.Value;
string attachmentUrl2 = Regex.Replace(reader.Value, "#", "");
string attachmentUrl = Regex.Replace(attachmentUrl2, ";", "");

Person person = new Person();
person.Name = personName;
person.Age = personAge;
person.Image = attachmentUrl;

reader.MoveToElement(); //Moves the reader back to the element node.

}
}
}
}
catch { }
}

That’s it, now we have our custom object loaded with data from a SharePoint list.

Setup a Silverlight 2 Development Box

Wednesday, July 15th, 2009

The release of Silverlight 3 adds some great new features (http://silverlight.net/GetStarted/overview.aspx), but one cumbersome obstacle now is the ability to continue development in Silverlight 2. With all the automatic updates and installation files forcing you to upgrade to 3, it was quite tough to get a new development environment up and running for developing Silverlight 2 applications for SharePoint.

Here’s a list of what I started out with on my server:

Windows Server 03, Enterprise Edition, SP2
WSS 3.0, SP1
MOSS 2007, MS Office Servers SP1
Visual Studio 2008 Professional, SP1
.NET 3.5 framework
Expression Blend

In order to get Silverlight 2 up and ready for development, you will need the following:

Silverlight 2.0 plug-in
Microsoft Silverlight Tools for Visual Studio 2008, SP1
Silverlight 2 SDK
Silverlight 2 Developer Run-Time

These are the locations I was able to find these installs as well as the ORDER in which I installed them. It is highly important that if any of your installation dialogs say “Silverlight 3″, that you DO NOT install them. If you are targeting Silverlight 2 application development, installing Silverlight 3 will cause problems.

Microsoft Silverlight 2 SDK
http://www.microsoft.com/downloads/details.aspx?familyid=8D933343-038F-499C-986C-C3C7E87A60B3&displaylang=en

Microsoft Silverlight Tools for Visual Studio 2008, SP1
http://www.microsoft.com/downloads/details.aspx?familyid=C22D6A7B-546F-4407-8EF6-D60C8EE221ED&displaylang=en

Microsoft Silverlight Developer Package
http://go.microsoft.com/fwlink/?linkid=129011
*This package will also go ahead and install the Silverlight 2 plug-in for you. If for some reason you need an exe for the standalone plugin, you can download an install for it here: http://rapidlibrary.com/index.php?q=silverlight+2+0+exe+yahoo