Skip to main content

Mark Stokes

Go Search
Home
People & Blogs
Twitter
Wiki
Events
Forums
Resources
Jobs
Support
Account
SP2010
  

Sharepoint Studio > People & Blogs > Mark Stokes > Categories
Adding Automatic SharePoint XML Intellisense to Visual Studio
Adding intellisense to Visual Studio for SharePoint based XML files (such as Feature.Xml files) is pretty easy. 
 
Open up the following directory (this is assuming Visual Studio 2008)
C:\Program Files\Microsoft Visual Studio 9.0\Xml\Schemas\
 
Add a new file called SharePointCatalog.xml
 
Add the following XML to that file:

<SchemaCatalog xmlns="http://schemas.microsoft.com/xsd/catalog">

<Schema href="file://c:/Program Files/Common Files/Microsoft Shared/web server extensions/12/TEMPLATE/XML/wss.xsd" targetNamespace="http://schemas.microsoft.com/sharepoint/"/>

<Schema href="file://c:/Program Files/Common Files/Microsoft Shared/web server extensions/12/TEMPLATE/XML/CamlQuery.xsd" targetNamespace="http://schemas.microsoft.com/sharepoint/"/>

<Schema href="file://c:/Program Files/Common Files/Microsoft Shared/web server extensions/12/TEMPLATE/XML/CamlView.xsd" targetNamespace="http://schemas.microsoft.com/sharepoint/"/>

<Schema href="file://c:/Program Files/Common Files/Microsoft Shared/web server extensions/12/TEMPLATE/XML/CoreDefinitions.xsd" targetNamespace="http://schemas.microsoft.com/sharepoint/"/>

</SchemaCatalog>

 
Save the file and restart Visual Studio.  Now you should automatically get SharePoint XML Intellisense.
Changing (or removing) the Toolbar from a ListViewWebPart
I have just spent a good couple of days on this problem and have finally come across an answer.
 
I am programmatically adding web parts to a SharePoint page and didn't want the Toolbar to show up.
 
Due to a bug in the SharePoint API the following code should, but doesn't, work:
 

SPView myView = list.Views["View Name"];

myView.Toolbar = "None";
  or

myView.Toolbar =
"Freeform";
  or
myView.Toolbar =
"Standard";
  or
myView.Toolbar =
"Full";

myView.Update();

 
Unfortunately, the Toolbar poperity of an SPView returns the InnerXml of the Toolbar node and we need to set an attribute on the parent node:
 

<Toolbar Type="None" />
  or
<Toolbar Type="Freeform" />
  or
<Toolbar Type="Standard" />
  or
<Toolbar Type="Full" />

 
So, how do we go about setting the toolbar property?
 
There are a lot of discussions out there on t'Internet, with a number of solutions that worked right up until the Infrastructure Updates were released which broke almost all of them.
 
The resources I was reading through and trying were:

There are many more, but these are the ones that led me to my final solution.

In the end I came across this post from Jalil Sear

Original Kudos needs to be sent out to Ton Stegeman and Brian Farhill for this post.

Ok, now that the acknowledgements are out of the way, what was the final solution?

I used the following method from Jalil's blog (its all his code)

public static void SetToolbarType(SPView spView, String toolBarType)
{
    spView.GetType().InvokeMember(
"EnsureFullBlownXmlDocument", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod, null, spView, null, System.Globalization.CultureInfo.CurrentCulture);

    PropertyInfo nodeProp = spView.GetType().GetProperty("Node", BindingFlags.NonPublic | BindingFlags.Instance);
   
XmlNode node = nodeProp.GetValue(spView, null) as XmlNode;
   
XmlNode toolbarNode = node.SelectSingleNode("Toolbar");

    if (toolbarNode != null)
   
{
       
toolbarNode.Attributes["Type"].Value = toolBarType;

        // If the toolbartype is Freeform (i.e. Summary Toolbar) then we need to manually 
       
// add some CAML to get it to work.
       
if (String.Compare(toolBarType, "Freeform", true, System.Globalization.CultureInfo.InvariantCulture) == 0)
       
{
           
string newItemString = "";
           
XmlAttribute positionNode = toolbarNode.OwnerDocument.CreateAttribute("Position");
           
positionNode.Value = "After";
           
toolbarNode.Attributes.Append(positionNode);

            switch (spView.ParentList.BaseTemplate)
           
{
               
case SPListTemplateType.Announcements:
                   
newItemString = "announcement";
                   
break;
               
case SPListTemplateType.Events:
                   
newItemString = "event";
                   
break;
               
case SPListTemplateType.Tasks:
                   
newItemString = "task";
                   
break;
               
case SPListTemplateType.DiscussionBoard:
                   
newItemString = "discussion";
                   
break;
               
case SPListTemplateType.Links:
                   
newItemString = "link";
                   
break;
               
case SPListTemplateType.GenericList:
                   
newItemString = "item";
                   
break;
               
case SPListTemplateType.DocumentLibrary:
                   
newItemString = "document";
                   
break;
               
default:
                   
newItemString = "item";
                   
break;
            
}

            if (spView.ParentList.BaseType == SPBaseType.DocumentLibrary)
            
{
               
newItemString = "document";
            
}

            // Add the CAML
            toolbarNode.InnerXml = @"<IfHasRights><RightsChoices><RightsGroup PermAddListItems=""required"" /></RightsChoices><Then><HTML><![CDATA[ <table width=100% cellpadding=0 cellspacing=0 border=0 > <tr> <td colspan=""2"" class=""ms-partline""><IMG src=""/_layouts/images/blank.gif"" width=1 height=1 alt=""""></td> </tr> <tr> <td class=""ms-addnew"" style=""padding-bottom: 3px""> <img src=""/_layouts/images/rect.gif"" alt="""">&nbsp;<a class=""ms-addnew"" ID=""idAddNewItem"" href=""]]></HTML><URL Cmd=""New"" /><HTML><![CDATA["" ONCLICK=""javascript:NewItem(']]></HTML><URL Cmd=""New"" /><HTML><![CDATA[', true);javascript:return false;"" target=""_self"">]]></HTML><HTML>Add new " + newItemString + @"</HTML><HTML><![CDATA[</a> </td> </tr> <tr><td><IMG src=""/_layouts/images/blank.gif"" width=1 height=5 alt=""""></td></tr> </table>]]></HTML></Then></IfHasRights>";
        
}

        spView.Update();

    }
}

Our original code then just has to call extract the WebPart View and call this method:

// Get Webpart View
System.Reflection.PropertyInfo ViewProp = wp.GetType().GetProperty("View", BindingFlags.NonPublic | BindingFlags.Instance);

SPView spView = ViewProp.GetValue(wp, null) as SPView;

WebParts.SetToolbarType(spView, "None")

For a little more completeness, here is how I add the ListViewWebPart to the page:

SPView myIssuesView = list.Views["My Issues"];

StringCollection viewFields = new StringCollection();
viewFields.Add(
"Title");
viewFields.Add(
"Issue Status");
viewFields.Add(
"Due Date");

SPView wpView = list.Views.Add("Temp View", viewFields, myIssuesView.Query, 10, false, false, SPViewCollection.SPViewType.Html, false);

ListViewWebPart wp = new ListViewWebPart();
wp.ListName = list.ID.ToString(
"B").ToUpper();
wp.Title =
"My Issues";
wp.ViewGuid = wpView.ID.ToString(
"B").ToUpper();

wpm.AddWebPart(wp, "LeftMiddleLeft", 1);

list.Views.Delete(wpView.ID);

// Get Webpart View
System.Reflection.PropertyInfo ViewProp = wp.GetType().GetProperty("View", BindingFlags.NonPublic | BindingFlags.Instance);

SPView spView = ViewProp.GetValue(wp, null) as SPView;

SetToolbarType(spView, "None");

I hope this goes some way to helping others with this issue.

Determining Your Version of SharePoint
 
This content is in the Wiki and will be updated there as more updates are released for WSS3.0 / MOSS 2007
 
If you need to determine which version of SharePoint you are running, you can do the following:
  • Central Administration -> Operations -> Servers In Farm -> Farm Information: Version
  • Site Settings -> Modify All Site Settings -> Site Information -> Database Schema Version
These two options give you the Database Schema Version which you can reference against the list below:
 
SP2
12.0.0.6421
Cumulative Update KB956056 & KB956057
12.0.0.6327
Infrastructure Update KB951695 & KB951297
12.0.0.6318
SP1 + KB948945
12.0.0.6303
SP1 + KB941274
12.0.0.6301
SP1 + KB941422
12.0.0.6300
SP1
12.0.0.6219
October 2007 public update
12.0.0.6039
August 24, 2007 hotfix
12.0.0.6036
RTM
12.0.0.4518
Beta 2
12.0.0.4017
Beta 2 TR
12.0.0.4407
Office 12 PDC Pre-beta
12.0.0.311
 
 
References
A question about Workflow in SharePoint

I recently received this query from a colleague and thought the answer would be usefull for others:

Hi Mark,

Could you share with me a print-screen of how a work-flow is configured in SP-2007?

I am wondering to know the level of detail we can set in the system to program a work-flow such as sequential authorizations, parallel authorizations, etc.

Thank you in advance,

A. Colleague

That is a really difficult request to answer. Workflow is so big in SharePoint that there isn’t really a screen shot that can be taken of all the options.

Workflows can be created in SharePoint Designer and there are a initial number of Conditions and Actions that are available, however it is possible to write new Conditions and Actions for use in our workflow, which means what we can do in workflow is limited only to the code that we can write.

When looking at the live Global Collaboration Portal we are not going to be using SharePoint Designer for our workflows (not initially at least) for a number of reasons, but mainly because Workflows created using SharePoint Designer can only be used against the one single list that it is assigned to when created. This makes creating and testing workflows in a development environment very tricky as once the workflow has been tested it needs to be recreated by hand, from scratch in the new next environment along (Local, Dev, UAT, Production, etc) which gives us the risk of human error in recreating them, and no clear path to re-install in a DR environment, let alone reuse in another area of the site.

Later in the life of the Global Collaboration Portal we may allow Power Users to create workflows in this way for small workflows that are only appropriate in that area, with larger workflows being created in Visual Studio.

This brings us nicely onto the preferred approach, which is to create our workflows in Visual Studio. This alleviates many of the issues outlined above, but does carry a higher development cost. Our workflows created in Visual Studio are contained in a Source Control application, can be compiled and deployed to many different environments, and many different lists and document libraries in those environments.

When creating these types of workflow, we start with a blank canvas allowing us to model any process we can imagine (in bother sequential and state-machine workflows) and have the same (including a few other) Conditions and Actions available to us that we had with out SharePoint Designer workflows, and again we can write new Conditions and Actions to cover situations not covered by out-of-the box modules.

Regards,
Mark Stokes
Configuring MySites

My blog is a bit unusal now, as I am trying to put all my content into the Wiki section of this site, so I will be using my blog to highlight new information I have posted there.

For starters, I have just collated a fair bit of information on configuring MySites and Profiles.

Find the article here:
Configuring MySites

Also, feel free to sign up, log in and edit the article to your hearts content. By us all contributing the information will just get better.

Mark.
SharePoint ServerTemplate values
Thanks to Evan Grimmett for this list:
 
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
 
 
Start a custom workflow from the context menu dropdown
This is a fantastic article and just what I needed to do!
 
 
 
Setting a SPListItem to expire programmatically
You can set SPListItems to expire at a date of your choosing.  This annot be done through the UI, but can be done programmatically.
 
Before the code below will work you have to set a couple of options on the list or document library.
 
You need to enable Require Content Approval  and Major and minor versions.
 
You need to enable content expiration on the List / Document Library information policy.  This can be done by going to the list settings page and clicking the Information management policy settings link and click the content type you wish to enable content expiry.  You can set a different policy for different content types.
 
When you are editing the policy, enable content expiration, set the retention period to be set programmatically and set the action you want to happen upon content disposition.
 
Now that is set up, we can set the expiry date.
 
I have an approval workflow and within the "Workflow Completed" action I set various properties on the SPListItem.
 
Here is how to do it.....
 
You need to add a reference to:
Microsoft Office Server DLC component
 
Located at:
c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\ISAPI\Microsoft.Office.Policy.dll
 
Then add the following using directive:
using Microsoft.Office.RecordsManagement.PolicyFeatures;
 
The following code snippet achieves this:
SPListItem item = this.workflowProperties.Item;

Expiration
.SetExpirationDateForItem(item, DateTime.Now.AddMonths(6), false);
 
And there you go.
 
More information here:
How to: Customize XSL for the Content Query Web Part

A very useful article on customising the Content Query Web Part look and feel:

http://msdn.microsoft.com/en-us/library/bb447557.aspx
Content Query Webpart won't show Publishing Pages
I have just come across a little bug.
 
I have a SharePoint site with some Publishing Webs and I tried to roll up my Publishing Pages with a Content Query Webpart, however Publishing Pages was not available in the List Type drop down list.
 
Apparently, if the Office SharePoint Server Publishing feature is not activated on the Root Site of the Site Collection then the Content Query Webpart won't let you roll up Publishing Pages.  It obviously checks this location to see if they are available or not, rather than determining if there there are any publishing webs in your site collection.