Archive

Posts Tagged ‘Development’

Example of how to get the URL to SharePoint 2007 Form Pages

February 11th, 2010 Dominick Cosgrove No comments

You can use the following syntax to get the fully qualified URL to a Form for a SharePoint List / Library.

SPList list = SPContext.Current.List;

SPListItem item = list[0];

item.Web.Url + "/" + item.ParentList.Forms[PAGETYPE.PAGE_DISPLAYFORM].Url + "?ID=" + item.ID

 

PAGETYPE is an enumeration of the SharePoint Forms:

PAGE_DEFAULTVIEW

Default view. Value=0.

PAGE_DIALOGVIEW

File dialog box view. Value=2.

PAGE_DISPLAYFORM

Display form for list items. Value=4.

PAGE_DISPLAYFORMDIALOG

Display form for a file dialog box. Value=5.

PAGE_EDITFORM

Edit form for list items. Value=6.

PAGE_EDITFORMDIALOG

Edit form for a file dialog box. Value=7.

PAGE_INVALID

Not used. Value= -1.

PAGE_MAXITEMS

Not used. Value=11.

PAGE_NEWFORM

New form for list items. Value=8

PAGE_NEWFORMDIALOG

New form for a file dialog box. Value=9.

PAGE_NORMALVIEW

Normal view. Value=1.

PAGE_SOLUTIONFORM

Solution form. Value=10.

PAGE_VIEW

View, including both default view and normal view. Value=3.

MS Loopback adapter

November 21st, 2009 Dominick Cosgrove No comments

If you need to browse your SharePoint site or for that matter any site, hosted on your VPC while you are not connected to a network, read on. If you are not connected to a network the VPC does not get an IP address issued hence why you cannot browse hosted sites. The solution to this is the MS Loopback Adapter. The following shows you how to set up your loopback adapter.

Add Loopback adapter

  1. Click Start, and then click Control Panel. Then click Add Hardware:
    image
  2. Select Yes, I have already connected the hardware:
    image
  3. From the list of devices select Add a new hardware device:
    image
  4. Select Install the hardware that I manually select from list (Advanced):
    image
  5. From the list of hardware types select Network Adapter:
    image
  6. From the list of Manufactures select Microsoft and from the list of Network Adapters select Microsoft Loopback Adapter:
    image
  7. Click Finish once the adapter is installed.
  8. The Loopback Adapter will now appear in you list of Network Connections:
    image

Configure Loopback Adapter

  1. In the Network Connections right mouse click on the newly created Loopback Adapter and select Properties;
  2. From the Properties select Internet Protocol (TCP/IP) and click Properties:
    image
  3. In the Properties add the IP address as follows:
    image 
  4. Click OK to commit the changes.

Configure VPC Network Adapter

  1. On Virtual PC (VPC) Console click Settings;
    image
  2. On the settings dialog box select Networking and then select Microsoft Loopback Adapter as the 1st Adapter. Click OK;
    image
  3. On the VPC click the Network icon in the task bar or navigate to the Network Connections through the control panel. The network icon may display a warning message “Limited or no connectivity”. Don’t worry about this at the moment;
    image
  4. On the Network Connections window, right mouse click on the Local Area Connection and click Properties;
    image
  5. On the TCP/IP settings for the Network adapter enter the following details. Click OK;image
  6. You will notice that the network icon on the desktop task bar no-longer displays the warning message;
  7. On the VPC, launch the Command Prompt and type IPConfig you should see that the VPC now has the IP address, subnet and gateway that you just entered;
    image
  8. From the VPC Command prompt ping 192.168.5.10 to confirm connectivity to the host;
    image 
  9. Ensure that you don’t have any network connectivity on your host computer, then from the Command Prompt ping the VPC 192.168.5.11 to confirm connectivity to the VPC;

Configure Host File

If your SharePoint (or website) uses Host Headers then you’ll need to edit your Host file:

  1.   Open your Host file C:\Windows\System32\Drivers\etc\host;
    image
  2. In the host file put the IP address of your VPC 192.168.5.11 and set the host in my case that is scratch;
     image
  3. You should now be able to browse your SharePoint (Web Site) hosted on a VPC even if you do not have connection to a network;
    image 

Top SharePoint Dev Productivity Apps

October 19th, 2009 Dominick Cosgrove No comments

Ok, so there are loads of these sort of blogs already out there, but hey thought I’d let you know the suite of tools that I’ve added to my arsenal. All these tools should help make your SharePoint life allot easier… they definitely save me a load of headaches over the years. Thanks to all the community folks for developing these tools, with out them our lives would be a lot harder.

SharePoint Inspector

SharePoint Inspector is a free tool to browse your SharePoint 2007 farm.

You can see objects composing its structure, get their properties by reflection, which can be very useful when you want to check if your code does what it should do.
You can use also some advanced features like activate/deactivate SharePoint features, add/remove event receivers, manage your recycle bin. Thanks to Gaetan Bouveret great utility.

CAML.NET IntelliSense

The purpose of this project is to extend the raw WSS xsd to include annotated documentation taken from the SharePoint SDK so that developers don’t have to break their train of thought while they go searching for information about each element. Thanks to John Holliday for providing this.

U2U CAML Query Builder

The tool will help you build, test and execute your CAML Queries. This version of the tool only let you build CAML queries for execution against lists. Thanks to those Belgium guys at U2U.

.Net Reflector

This is something that should be in any .Net developer tool box. .NET Reflector enables you to easily view, navigate, and search through, the class hierarchies of .NET assemblies, even if you don’t have the code for them. With it, you can decompile and analyze .NET assemblies in C#, Visual Basic, and IL.

BDC Meta Man

BDC Meta Man is the first Business Data Catalog tool for all SharePoint Developers and Administrators interested in line of business data integration with SharePoint. Without writing a single line of code you can be viewing and searching across your business data through Microsoft Office SharePoint Server 2007 in minutes.

This is a great tool provided by the guys from Lightening Tools. The free to download version gives you some limited functionality.

Nick Swan and Brett Lonsdale the cofounders of Lightening tools have also produced a great book on the BDC “SharePoint 2007 Developer’s Guide to Business Data Catalog”. They can also be heard on the Excellent SharePoint Pod Show with co-host Rob Foster. Definitely check it out.

WSPBuilder

A SharePoint Solution Package (WSP) creation tool for WSS 3.0 & MOSS 2007
- No more manually creating the manifest.xml file.
- No more manually specifying the DDF file.
- No more using the makecab.exe application.

Carsten Keutmann you’re a legend… what more can I say!

SharePoint Manager 2007

The SharePoint Manager 2007 is a SharePoint object model explorer. It enables you to browse every site on the local farm and view every property. It also enables you to change the properties (at your own risk). This is a very powerful tool for developers that like to know what the SharePoint holds of secrets. Another great tool from Carsten Keutmann.

Fiddler

Fiddler is a Web Debugging Proxy which logs all HTTP(S) traffic between your computer and the Internet. Fiddler allows you to inspect all HTTP(S) traffic, set breakpoints, and "fiddle" with incoming or outgoing data.

AppPool Manager Neat little tool from Spencer Harbar.
SPSource

SPSource is a tool for SharePoint developers to assist in the creation of WSS Solution Packages (WSPs) allowing for the use SharePoint Designer and the SharePoint web UI to make quick changes to items, then push those items into Visual Studio for later compilation into a WSP. Thanks to Jeremy Thake.

STSAdm Extensions A must have suite of STSAdm commands from Gary Lapointe. Great for those SharePoint Administrators out there.
SPTraceView

SPTraceView analyses in real time the ULS trace messages coming from all MOSS components and can notify you using a balloon-style tray bar messages when something of interest happens.

SP Dispose Checker Tool

SPDisposeCheck is a tool to help you to check your assemblies that use the SharePoint API so that you can build better code. It provides assistance in correctly disposing of certain SharePoint objects to help you follow published best practice.

SharePoint Installer

This project is a Windows application for an eased and more user friendly installation and deployment of SharePoint 2007 solution files to a SharePoint server farm. Distribute your SharePoint solution files with this installation program instead of a raw script using STSADM.EXE to install and deploy the solution.

SharePoint Search Service Tool

The SharePoint Search Service Tool is a rich web service client that allows a developer to explore the scopes and managed properties of a given SharePoint Search SSP, build queries in either Keyword or SQL Syntax, submit those queries and examine the raw web service results. This tool can be useful in troubleshooting and verifying the behaviour and configuration of a SharePoint environment.

CodeRush

CodeRush for Visual Studio® .NET will help you create sophisticated code blocks in seconds and extend code templates instantly. CodeRush will complete identifiers as you type and expand or contract selections logically. With CodeRush, you will be able to instantly place selected code inside Try/Catch blocks, Regions and your own custom wrappers with ease.

ReSharper

ReSharper provides solution-wide error highlighting on the fly, instant solutions for found errors, over 30 advanced code refactorings, superior unit testing tools, handy navigation and search features, single-click code formatting and cleanup, automatic code generation and templates, and a lot more productivity features for C#, VB.NET, ASP.NET, XML, and XAML.

SharePoint Skinner Helps you define the theme css for your custom SharePoint sites.
Visual Round Trip Analyser

The Visual Round Trip Analyzer tool helps web developers and testers visualize the download of their page, identify best practices and changes that improve web performance. The network Round-Trip between the client and server(s) is the single biggest impact to web page performance – much greater than server response time.

YSlow YSlow analyzes web pages and suggests ways to improve their performance based on a set of rules for high performance web pages.

SharePoint Feature Scopes

August 6th, 2009 Dominick Cosgrove No comments

How to add a SharePoint WebPart to a group other than Miscellaneous

April 20th, 2009 Dominick Cosgrove No comments

By default, SharePoint web parts are always put into a web part group called “Miscellaneous”.

All you need to do is locate your Feature Element Manifest XML file and add a Property Element called Group and assign it a value. This is normally the XML file that is in your WebPart Folder.

Nice and easy hey… enjoy :)

Get SharePoint Installation Directory Path

March 25th, 2009 Dominick Cosgrove No comments

If you need to get the SharePoint Installation Directory Path then you can use the SPUtility.GetGenericSetupPath method. For instance if you needed to get the path to a features directory to load some XML you could use the following syntax:

string FeaturesPath = SPUtility.GetGenericSetupPath(@”TEMPLATE\FEATURES\” + FeatureName)

The SPUtility Class is full of static methods for assisting you in your SharePoint Development.

SPDisposeCheck

March 2nd, 2009 Dominick Cosgrove No comments

Every SharePoint Developer should have SPDisposeCheck Tool in there arsnel! This tool, developed by the guys on the SharePoint Team will intergoate your compiled .dll’s to ensure that you are correctly disposing of SharePoint objects, primarily SPSite and SPWeb. Why do we need to dispose of SharePoint object, well from the horses mouth as such :

“Several of the Windows SharePoint Services objects, primarily the SPSite class and SPWeb class objects, are created as managed objects. However, these objects use unmanaged code and memory to perform the majority of their work. The managed part of the object is much smaller than the unmanaged part. Because the smaller managed part does not put memory pressure on the garbage collector, the garbage collector does not release the object from memory in a timely manner. The object’s use of a large amount of unmanaged memory can cause some of the unusual behaviors described earlier. Calling applications that work with IDisposable objects in Windows SharePoint Services must dispose of the objects when the applications finish using them. You should not rely on the garbage collector to release them from memory automatically.”

Roger Lamb has an excellent blog article - SharePoint 2007 and WSS 3.0 Dispose Patterns by Example

Add SPDisposeCheck to Visual Studio

Visual Studio IDE allows you to add External Tools such as SPDisposeCheck. The follow steps explain how:

1. In Visual Studio select Tools | External Tools

2. Add the following settings:

Title:  SPDisposeCheck
Command: C:\Program Files\Microsoft\SharePoint Dispose Check\SPDisposeCheck.exe
Arguements: $(TargetName)$(TargetExt)
Initial Directory: $(TargetDir)
Use Output Window: Checked

SP Dispose Check External Tools

SP Dispose Check External Tools

Reference

Introduction to Using Disposable Windows SharePoint Services Objects

SharePoint ServerTemplate ID’s

January 26th, 2009 Dominick Cosgrove No comments

This is a quick reference for all the SharePoint Server Template IDs.

100 Generic list   101 Document library
102 Survey   103 Links list
104 Announcements list   105 Contacts list
106 Events list   107 Tasks list
108 Discussion board   109 Picture library
110 Data sources   111 Site template gallery
112 User Information list   113 Web Part gallery
114 List template gallery   115 XML Form library
116 Master pages gallery   117 No-Code Workflows
118 Custom Workflow Process   119 Wiki Page library
120 Custom grid for a list   130 Data Connection library
140 Workflow History   150 Gantt Tasks list
200 Meeting Series list   201 Meeting Agenda list
202 Meeting Attendees list   204 Meeting Decisions list
207 Meeting Objectives list   210 Meeting text box
211 Meeting Things To Bring list   212 Meeting Workspace Pages list
300 Portal Sites list   301 Blog Posts list
302 Blog Comments list   303 Blog Categories list
850 Page Library   1100 Issue tracking
1200 Administrator tasks list   2002 Personal document library
2003 Private document library      

You can get the List Templates using SPWeb.ListTemplates

References:

http://msdn.microsoft.com/en-us/library/ms415091.aspx

Setting the value of a BDC field Programmatically

January 21st, 2009 Dominick Cosgrove No comments

You cannot set the value of a BDC (Business Data Catalog) field in the same way that you set standard fields in SharePoint e.g:

SPListItem item = myList.Items.Add();
item["Title"] = "Product Information";

Instead you must use the EncodeEntityInstanceId method of the EntityInstanceIdEncoder class of the  Microsoft.Office.Server.ApplicationRegistry.Infrastructure class library. First you can detect if your field is a BDC field by:

if(item.Fields["MyField"].TypeAsString == "BusinessData")

You then need to:

//Get a reference to the field
SPField myField = spItem.Fields["EmployeeID];

//Get the entity Name for the field
XmlDocument xmlData = new XmlDocument();
xmlData.LoadXml(myField.SchemaXml);
String entityName = xmlData.FirstChild.Attributes["RelatedFieldWssStaticName"].Value;

//Set the Entity Instance value
spItem[entityName] = EntityInstanceIdEncoder.EncodeEntityInstanceId(new object[] { "123456" });

//Set the field display value
spItem["EmployeeID"] = "123456;
1 comments  Saturday, January 24, 2009

Connected WebParts – No Filtered Parameters

Posted by Dominick Cosgrove at 9:05 PM Labels: ,

OK this may be obvious but it caught me out and god knows it caused me to tear my hair out for a while.

I was creating a custom consumer WebPart that I wanted to connect to a URL and BDC Filter WebParts. There are loads of examples out there of how to do this. Basically Windows SharePoint Services makes use of the connection framework and provides additional interfaces called IFilterValues and IItransformableFilterValues to make it easy to create Web Part connections for filtering scenarios.

The issue I had was once I implement the code as per the various examples on the web, there were no filter parameters available to when you configure the connection.

image

The problem lies with the ConsumerParameterCapabilities Enumeration, which is used by a consumer Web part to indicate supported filter parameter capabilities. The samples on the web all seem to use:

ConsumerParameterCapabilities.SupportsMultipleValues

and

ConsumerParameterCapabilities.SupportsAllValue

Unfortunately this did not seem sufficient for the BDC and URL filter WebParts, after some trail and error I established that the minimum required is:

ConsumerParameterCapabilities.SupportsAllValue

or

ConsumerParameterCapabilities.SupportsEmptyValue

How ever it does work if you specify all ConsumerParameterCapabilites. The ConsumerParameter method allows you to have or statements so you can effectively set the parameters like this:

parameters.Add(new ConsumerParameter(
                    "Personnel Number",
                    ConsumerParameterCapabilities.SupportsAllValue
                    |
                    ConsumerParameterCapabilities.SupportsEmptyValue
                    )

or

parameters.Add(new ConsumerParameter(
                    "Personnel Number",
                    ConsumerParameterCapabilities.SupportsAllValue
                    |
                    ConsumerParameterCapabilities.SupportsEmptyValue
                    |
                    ConsumerParameterCapabilities.SupportsMultipleValues
                    |
                    ConsumerParameterCapabilities.SupportsSingleValue
                    )
                );

So to summaries, make sure you are using the correct ConsumerParameterCapabilities for your provider webpart or else you will not see the parameters you are expecting to see.

References

Writing a Simple Filter Consumer Web Part Sample

MOSS 2007 Filter webparts part 1 – create your own provider and consumer

Query Child Content Types in your CAML Query

January 15th, 2009 Dominick Cosgrove No comments

The Content Query Web Part that ships with MOSS and is enabled with the Publishing Feature has an option to include the child content types of that content type in filtering the data. I wanted to replicate this functionality in my own WebPart that utilized the SPSiteDataQuery to query the site. The SPSiteDataQuery accepts a CAML query to filter the results.

image

It is easy enough to query for all documents in a site that are of content type x:

<Where>
  <Eq>
    <FieldRef Name=’ContentType’/>
    <Value Type=’Text’>HR Document</Value>
  </Eq>
</Where>

But what happens if you want to query all children of content type x. In this example if you had CV, Application Form e.t.c. which all inherited from HR Document how do you build your query. You can add each additional Content Type into the WHERE clause of the CAML query, but this is an convoluted approach as any time you add a new child content type you’ll have to modify your CAML query.

The answer lies with how the ContentTypeID is constructed in SharePoint. The ContentTypeID is a concatenation of parent child ContentTypeIDs, this is to say that a ContentTypeID is composed of its parent ContentTypeID post fixed with a  it’s own identifier.

Content Type Parent Content Type Content Type ID
System   0x
Item System 0×01
Document Item 0×0101
HR Document Document 0×0101002C3431777FFD0742A58D02ABC9C5FA62
CV HR Document 0×0101002C3431777FFD0742A58D02ABC9C5FA6201
Application Form HR Document 0×0101002C3431777FFD0742A58D02ABC9C5FA6202

Knowing this you can construct a CAML query that uses the <BeginsWith> select statement.

To return all Documents you can use the following query:

<Where>
   <BeginsWith>
     <FieldRef Name=’ContentTypeId’/>
     <Value Type=’Text’>0×0101</Value>
   </BeginsWith>
</Where>

To return all HR Documents you can use the following query:

<Where>
   <BeginsWith>
     <FieldRef Name=’ContentTypeId’/>
     <Value Type=’Text’>0×0101002C3431777FFD0742A58D02ABC9C5FA62</Value>
   </BeginsWith>
</Where>

You can find the ContentTypeID by going to Site Actions | Site Settings | Site Content Types, and select the parent content type you are interested in. In the URL you will see the ContentTypeID in the page URL. For example:

image