September 24, 2009

SharePoint Lookup Field Restricted to “Single Line of Text” Items

Filed under: Sharepoint — Tags: , , , , , , , — Tim Lefler @ 5:28 pm

OMG (A little Blog texting I guess)  Is Microsoft serious!  As usual SharePoint seems to get you 80% of the way there and then leaves you hanging or leaves you deeply involved in the complex mysticism that is Visual Studio!  It seems to me that a commonly required technique would be to reference other fields from a different SharePoint list…. these fields might be date time, single line of text, multi-line, number, etc….  For me, in particular, I want to reference a Date and Time column from another list!

Unfortunately Look up fields in a SharePoint list will only reference fields that are of type “Single Line of Text”.

What crap is that?  Once again something that seems very basic and should be handled, forces us to break out Visual Studio and develop our own solution!!  I hope 2010 will bring some improvements!!

There has been publicized on the internet a bit of a hack around this problem, you trick Sharepoint into looking up to a different field type. You create the column as a single line of text, create a look-up to it then change the target field from a single line of text to the data type you require. This is unsupported by Microsoft and I think it is a best practice to treat the column you are adding as the data type represented.  We are a production shop and don’t want to use hacks because of fears of breaking stuff on next release!!  So I have not verified this will work.

Sigh…. no solution yet but will keep you posted if I find one.

Javascript routine to fix paging problem where List View WebPart clears the Query String

Filed under: Development — Tags: , , , , , , — Tim Lefler @ 2:02 pm

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…)

How to Programatically Assign a Value to a SharePoint List’s Date and Time Field

Filed under: Development — Tags: , , , , , , , , , , — Tim Lefler @ 12:59 pm

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.

September 22, 2009

How to change webservice to use FQDN instead of Netbios name

Filed under: Information Technology — Tags: , , , , , , , , , — Tim Lefler @ 11:54 am

We have a webservice that we want to connect to using HTTPS and the FQDN.  This causes a problem when using SSL specifically because some of the schema locations have the NetBIOS name referenced and SSL will fail because the certificate does not match the NetBIOS host-name.  Below, notice how the NetBIOS name “corpweb” is referenced instead of the FQDN that will be expected during SSL negotiation.

To display this info I simply referenced:

https://corpweb.domain.com/WebReportingService/WebFeed.svc?wsdl

Netbios in wdsl

Netbios in wdsl

The NetBIOS name is automatically used by the WCF.  To get the webservice to use the FQDN you need to change the IIS metabase bindings. (more…)

September 18, 2009

Porting Content Databases between SharePoint Farms and how to deal with those tricky STS#? Options

Filed under: Sharepoint — Tags: , , , , , , , , , , , — Tim Lefler @ 8:05 pm

Recently I was trying to port a content database to a new farm and wanted to create a site on the farm that pointed to a restored SQL database on my SQL Server.

So my steps were as follows:

  1. Backup original SQL Content DB using SQL Management Tool
  2. Copy the Content DB backup up file to the other SQL DB Server
  3. Use SQL management tool on the new server to restore to a database that didn’t exist
  4. Run the following “stsadm” command to attach a new site to this SQL Content DB.
stsadm -o createsiteinnewdb -url http://sites/SomeSite -owneremail  SharePoint@Someplace.com
       -ownerlogin somplace\sharepointowner -sitetemplate STS#0 -title "Name of the site"
       -databaseserver mosssqlsvr
       -databasename Name_of_restored_DB

(more…)

Trick to Edit Sharepoint Web Pages within the Browser when the “Edit Page” is Greyed Out

Filed under: Sharepoint — Tags: , , , , , , , , , , , , — Tim Lefler @ 1:25 pm

This is a trick to Edit SharePoint Web Pages within the Browser when the “Edit Page” is greyed Out.  We like to add Java script to Content Editor Web Parts and not to the actual source of a page within SharePoint Designer.  For most pages this is not a problem, but for the pages associated with a List like “NewForm.aspx” the “Edit Page” selection under “Site Settings” is greyed out.

"Edit Page" Greyed Out

"Edit Page" Greyed Out

Since the source of a Content Editor Web Part can only be edited using the browser, this makes it hard for us to add Java script in our typical manor. (more…)

September 16, 2009

SharePoint Task Notifications Not Working After URL Change

Filed under: Sharepoint — Tags: , , , , , , , — Tim Lefler @ 5:16 pm

In our situation we migrate content databases on a regular basis between our MOSS Sandbox environment to our Production and Staging environments.  I ran into a situation where we ported a Sandbox content database to the Staging environment so we could begin unit testing.  Although external Email was functioning, proven by other alerts on list items, our workflow task notifications were not being sent.

Found the following Log entry that seemed to be relavant:

09/16/2009 15:45:24.70 OWSTIMER.EXE (0×0660)                              0x0DDC                Windows SharePoint Services   Timer                                         9e99      High       AlertsJob failed to initialize site collection for Subscription id: {F51BE5D2-8142-4826-A7CC-DE03C7BA17C8}. Possibly incorrect siteurl http://mosssbx/sites/Test for site collection Id: {352E8E65-1A15-4953-98F6-4D2899492DB1},HRESULT 0×80070002

So I knew we had a database entry somewhere still pointing at my mosssbx site! (more…)

September 10, 2009

Considerations for Adding BDC data to a list

Filed under: Development — Tags: , , , , , — Tim Lefler @ 6:37 pm

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).

HurricaneSy,bple

(more…)

September 3, 2009

Technique for Copying a SharePoint Document Library Item to another Document Library

Filed under: Development — Tags: , , , , , , , — Tim Lefler @ 12:57 pm

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

Powered by WordPress