The problem:
When you have a List View WebPart on a SharePoint page that has paging enabled, when you click on the paging button to move forward or backward in the List view, the webpart clears any existing query string parameters when posting back to get the next page of information. This is a big problem if the page relies on the query string to display dynamic information.
So, if I have a custom aspx page that displays dynamic information about an item with ID=5, I would have a URL like this:
http://machine.domain.com/sites/somesite/CustomPage.aspx?ID=5
When you click on the “Next Page” button on the List View Webpart it wants to clear the query string and navigate to something that looks similar to this:
http://machine.domain.com/sites/somesite/CustomPage.aspx?Paged=TRUE&p_ID=38&View={5E53C811-1C34-4F1D-B1CB-E83E92712CEF}&FolderCTID=0×012001&PageFirstRow=9
Notice that my CustomPage.aspx “ID=5″ parameter is missing!!
A Technique to Fix the Problem:
Rather than code a custom webpart the following javascript can be placed in the source of a Content Editing Web Part directly below the List View Webpart. When it executes it will re-write all the URLs to include the original query string.
(more…)
To set a Date and Time field for SharePoint list items in your code you have to guarantee that dates are in invariant format or you will have problems. It is possible to assign value of DateTime type to this field or a string.
Invariant format is: MM/dd/yyyy HH:mm:ss
If you want to assign the date as a string to SharePoint’s DateTime type field then you must format this string as an invariant date. The following code snippet sets a workflow item’s Date and Time column to the current time.
Imports System.Globalization
workflowproperties.Item["TheDate"] = DateTime.Now.ToString(DateTimeFormatInfo.InvariantInfo)
workflowproperties.Item.SystemUpdate()
If you make sure dates are always in invariant format then assigning values to DateTime fields is easy.
Most of this info came from this post:
http://vspug.com/joed/2008/02/28/be-careful-with-the-bdc-hurricane-button/
When you add a Business Data Catalog (BDC) column to a custom list, in the list view column headings you will see an icon with two green circular arrows next to the BDC column – it looks a little like the symbol for a hurricane. This is the “BDC Update” (or “refresh” button).

(more…)
This was kind of more difficult than I would have expected. This is the technique I’ve been able to use successfully to copy document library list items from one list to another. I had to work through a number of problems including a confusing error from Visual Studio: “To add an item to a document library, use SPFileCollection.Add()”
SPFileCollection? WTF, I thought I was dealing with a List!!
Below is the coding technique I finally was able to get to work.
- Add a new file to the document library first using the SPFileCollection class.
- From the file get the SPListItem object for the new item
- Update the fields of the new list item
- Use newitem.Update to commit the changes
' Code to COPY a document library list item to a new document library List
' Get a reference to the destination List.
Dim destlist As SPList = workflowProperties.Web.Lists("Destination")
Dim sourceitem As SPListItem = workflowProperties.Item
Dim filebytes As Byte()
Dim newitem As SPListItem
' Gets the source file from the source list
Dim thefile As SPFile = sourceitem.File
Dim ct As SPContentType
Dim field As SPField
Dim destrelativeurl As String = destlist.RootFolder.Url & "/" & sourceitem.File.Name
' Suck the source file into binary array
filebytes = sourceitem.File.OpenBinary
' This creates an entry in the destination list and returns SPFile obj
thefile = destlist.RootFolder.Files.Add(destrelativeurl, filebytes, True)
' We can now use the SPFile obj to get the new list entry.
newitem = thefile.Item
' cycle through each of the fields setting them to be the same if the
' are fields that are not Read Only
For Each field In sourceitem.Fields
If Not field.ReadOnlyField Then
Try
' Set the matching field in the destination list
' The Source list might not have the same number of columns so we enclose this
' in a TRY so that if a column doesn't exist in the destination it continues.
newitem(field.Title) = sourceitem(field.Title)
End Try
End If
Next
' Commit the changes
newitem.Update()
Many thanks to this blog post for pointing me in the right direction
Assembled from a post here on SharePoint 2007 maximum limitations:
| Entity |
Max Value |
| Site Name |
128 Characters |
| Site URL |
255 Characters |
| Display Name |
128 Characters |
| Connection String |
384 Characters |
| Email Address |
128 Characters |
| Version Numbers |
64 Characters |
| Virtual Server Friendly Name |
64 Characters |
| SQL Database Name |
123 Characters |
| SQL Database Column |
128 Characters |
| SendEmail Activity Email Body |
2048 Characters |
| SQL Database Table Name |
128 Characters |
| SQL Role Name |
128 Characters |
| Server Name |
128 Characters |
| Windows User Name |
300 Characters |
| Windows Password |
300 Characters |
| Dependencies per Object |
32 Objects |
| Zone Enumeration Value |
4 Zones |
| Default SQL Timeout |
300 Seconds |
| Number of Simultaneous Workflows that can be run* |
15 |
(more…)
SharePoint uses lot of comlicated underlying schemas, delimiters and formats when storing field data into the database. Unfortunately, you need to access different fields in diferent ways! Below are the techniques I’ve used to access field information using best pratices…. kudos to this post for most of the technical beginning:
http://sharepointcodeblock.blogspot.com/2008/07/properly-populating-and-retrieving.html
I’ve added what I’ve learned since to try to make this as complete as possible.
(more…)
Here is a VB.Net code snippet to delete all of the tasks associated with a SharePoint Workflow. I needed to be able delete all of the tasks associated with the workflow when my state machine workflow changed to a different state. This technique worked for me, simply make the procedure below a “ExecuteCode” method for a Code Activity:
Private Sub RemoveEscalationTask(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim taskcollection As SPWorkflowTaskCollection = workflowProperties.Workflow.Tasks
Dim taskindex As Integer = taskcollection.Count
Dim thetask As SPWorkflowTask
Try
' Cycle through all of the escalation tasks and delete them
While taskindex > 0
thetask = taskcollection(taskindex - 1)
thetask.Delete()
taskindex = taskindex - 1
End While
Catch ex As Exception
End Try
End Sub
Recently, I was debugging one of my SharePoint workflows using Visual Studio 2008 and could not figure out why breakpoints I had set within my code were not firing. In a previous post, I talked about reasons why your delay activity might not be firing at all but what if your activity fires but your breakpoints do not?
By default when inter-actively debugging a workflow, Visual Studio attaches to the IIS worker process, w3wp.exe. If you use any “Delay” activities within your workflow, this gets triggered and ran by the Windows SharePoint Services Timer process, owstimer.exe. Because the owstimer.exe process is loading and executing a separate copy of the assembly from the Global Assembly Cache (GAC) visual studio is not monitoring the correct instance of the assembly for breakpoints.
This complicates the debug process a little. You cannot simply step through the code execution from beginning to end. Instead, as the developer, you need to have a good understanding of what to attach to when debugging events triggered by the owstimer process or w3wp process. Follow the procedure below to attach visual studio to the owstimer process and allow breakpoints to be handled by the correct copy of the assembly. (more…)
Really struggled with this one for a few days. Had a Visual Studio 2008 workflow I was developing and was just trying to get a Delay Activity to fire during a state machine event activity. Just could not seem to get the Delay activity to wake up. Below is the high-level view of my state machine workflow:

State Machine Workflow Diagram
(more…)
Recently I was working on a custom visual studio SharePoint State machine workflow in which I wanted to programtically set the To, From, & Body fields of the SendEmail activity. The “To” field was derived from a List column of the “People and Groups” type and multiple selections was enabled. This turned out to be quite a bit more challenging than I ever thought it would be, so I figured I’d post what I’ve learned in case anyone else could benefit.
(more…)