Sharepoint 2010 – Meeting Workspace Templates with Content

August 8, 2012 § Leave a comment

Very frustrating thing about meeting workspace templates is that you can’t include content in the template. Of course, the first time you make a meeting workspace template, you’re going to want to include content. For instance, you make a meeting workspace template for a particular group, and that group always has the same members in it. It would be nice to have the template pre-populate the attendee list so that you don’t have to enter it once the meeting workspace has been created.

So, since this is a pain in the ass, and we need it to work, let’s hack it.

I found it easier to start with a template that is not derived from a meeting workspace template. So create a new site, modify it to your satisfaction (including whatever content you want), then save the site as a template. Download the .wsp to your local system and extract it using a tool like iZarc.

Go ahead and create another site, using the Blank Meeting Workspace template. Don’t modify it – just save the site as a template. Downlod the .wsp to your local system and extract it using a tool like iZarc.

Changes:

[WHATEVER]WebTemplate\Elements.xml
Change BaseTemplateID=”2″
Change BaseTemplateName=”MPS”

It helps to have the second wsp for comparison here.
[WHATEVER]ListInstances\Elements.xml
Add the “Meeting Series” and “Workspace Pages” list instances.

[WHATEVER]ListInstances\Feature.xml
Add the “Meeting Series” and “pages” ElementFile locations.

[WHATEVER]ListInstances\Files
Add the pages folder (and its contents)

[WHATEVER]ListInstances\Files\Lists
Add the “Meeting Series” folder (and its contents)

Use a tool like iZarc to package the whole folder back into a .cab file. Rename the .cab file to .wsp. Upload it to the solution gallery.

Now you can create a meeting workspace with this template, and the content will be included.

TADA!

Advertisements

DBNull is stupid

January 28, 2011 § 1 Comment

DBNull is stupid. If you’re using it, stop.

Take this basic code:

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim obj1 As Object

        Dim obj2 As Object

 

        obj1 = "a"

        obj2 = "b"

 

        Try

            AssignValue(obj1, obj2)

            MessageBox.Show(obj2.ToString())

        Catch ex As Exception

            MessageBox.Show(ex.ToString())

        End Try

    End Sub

 

    Public Sub AssignValue(ByVal obj1 As Object, ByRef obj2 As Object)

        If (obj1 <> obj2) Then

            obj2 = obj1

        End If

    End Sub

End Class

 

This is a somewhat contrived example, but basically, we want to give obj2 the value that obj1 has. We do a simple check to make sure that they aren’t the same before bothering to do so. This is more important in code where you’re setting a property (rather than just a variable) which may execute some other code, like setting a dirty flag or even writing to persistent storage.

Anyway, the code executes, and obj2 is assigned the value of obj1 (“a”). So what’s the problem? Let’s change the value of obj1 to DBNull.Value.

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim obj1 As Object

        Dim obj2 As Object

 

        obj1 = DBNull.Value

        obj2 = "b"

 

        Try

            AssignValue(obj1, obj2)

            MessageBox.Show(obj2.ToString())

        Catch ex As Exception

            MessageBox.Show(ex.ToString())

        End Try

    End Sub

 

    Public Sub AssignValue(ByVal obj1 As Object, ByRef obj2 As Object)

        If (obj1 <> obj2) Then

            obj2 = obj1

        End If

    End Sub

End Class

 

Should be no problem, right? The AssignValue sub will be called and obj2 will be assigned a value of DBNull.Value. Except that it doesn’t. Actually, what you get is an exception that states:

{“Operator ” is not defined for type ‘DBNull’ and string “b”.”}

Well, crap. Ok, we’ll check for DBNull.Value in our AssignValue sub.

    Public Sub AssignValue(ByVal obj1 As Object, ByRef obj2 As Object)

        If (IsDBNull(obj1) AndAlso Not IsDBNull(obj2)) OrElse

            (Not IsDBNull(obj1) AndAlso IsDBNull(obj2)) OrElse

            obj1 <> obj2 Then

 

            obj2 = obj1

        End If

    End Sub

Run our code again and everything works great. Wait, what if obj1 and obj2 are both set to DBNull.Value?

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim obj1 As Object

        Dim obj2 As Object

 

        obj1 = DBNull.Value

        obj2 = DBNull.Value

 

        Try

            AssignValue(obj1, obj2)

            MessageBox.Show(obj2.ToString())

        Catch ex As Exception

            MessageBox.Show(ex.ToString())

        End Try

    End Sub

Another exception, of course!

{“Operator ” is not defined for type ‘DBNull’ and type ‘DBNull’.”}

Ack! Seriously? Ok, let’s change our AssignValue sub again. We’ll check to see if obj1 is DBNull while obj2 is not, or obj2 is DBNull while obj1 is not, or both obj1 and obj2 are not DBNull and not equal to each other.

    Public Sub AssignValue(ByVal obj1 As Object, ByRef obj2 As Object)

        If (IsDBNull(obj1) AndAlso Not IsDBNull(obj2)) OrElse

            (Not IsDBNull(obj1) AndAlso IsDBNull(obj2)) OrElse

            (Not IsDBNull(obj1) AndAlso Not IsDBNull(obj2) AndAlso obj1 <> obj2) Then

 

            obj2 = obj1

        End If

    End Sub

Wow, we’ve finally managed to implement what should be a simple comparison and we only had to do 5 comparisons to do it. Maybe it’s just me, but this seems excessive for what we’re trying to do. I understand that it’s necessary to represent null database values in our objects, but generics (and therefore Nullables) were introduced in .NET 2.0 – stop using DBNull.

Twitter, jQuery, and Performance

January 21, 2011 § Leave a comment

This writeup by John Resig concerning Twitter’s recent performance problems is an interesting read. It points out that some changes in jQuery 1.43 were responsible for part of the performance degradation, but the larger problem had more to do with how jQuery was being used. John points out two things that we would all do well to pay attention to.

  1. It’s a very, very, bad idea to attach handlers to the window scroll event.
  2. Always cache the selector queries that you’re re-using.

If you’d like to explore this topic further, this jQuery performance optimization video by Addy Osmani is great. You’ll need to block off half an hour or so to watch it, but it offers some excellent tips that are really useful if you’re in and out of jQuery on a regular basis.

MVC, mobile views, and RAZR

January 21, 2011 § 1 Comment

I thought that this whitepaper on making your MVC web application mobile friendly was a very good read. The only thing that struck me was the section on remembering the user’s preference regarding using the mobile presentation versus the standard presentation:

It’s often convenient to redirect mobile visitors to the mobile pages only on the first request in their browsing session (and not on every request in their session), because:

  1. You can then easily allow mobile visitors to access your desktop pages if they wish – just put a link on your master page that goes to “Desktop version”. The visitor won’t be redirected back to a mobile page, because it’s no longer the first request in their session.
  2. It avoids the risk of interfering with requests for any dynamic resources shared between desktop and mobile parts of your site (e.g., if you have a common Web Form that both desktop and mobile parts of your site display in an IFRAME, or certain Ajax handlers)

To do this, you can place your redirection logic in a Session_Start method. For example, add the following method to your Global.asax.cs file…

I frequently browse the web on my Android phone – in fact, I probably browse the web more on my phone than I do on my computer. I don’t want my mobile/standard preference stored in the session. I want it stored in a persistent cookie so that I don’t have to reset my preference every time I visit your site. This isn’t even difficult – here is an excellent reference to using cookies with .NET.

The section regarding the different methodologies for presenting mobile specific pages talks about using different Razor views for mobile/standard:

Since the Model-View-Controller pattern decouples application logic (in controllers) from presentation logic (in views), you can choose from any of the following approaches to handling mobile support in server-side code:

  1. Use the same controllers and views for both desktop and mobile browsers, but render the views with different Razor layouts depending on the device type. This option works best if you’re displaying identical data on all devices, but simply want to supply different CSS stylesheets or change a few top-level HTML elements for mobiles.
  2. Use the same controllers for both desktop and mobile browsers, but render different views depending on the device type. This option works best if you’re displaying roughly the same data and providing the same workflows for end users, but want to render very different HTML markup to suit the device being used.
  3. Create separate areas for desktop and mobile browsers, implementing independent controllers and views for each.This option works best if you’re displaying very different screens, containing different information and leading the user through different workflows optimized for their device type. It may mean some repetition of code, but you can minimize that by factoring out common logic into an underlying layer or service.

If you want to take the first option and vary only the Razor layout per device type, it’s very easy…

The Razor views look very slick, and unfortunately, I haven’t had much time to play with them yet. Telerik recently posted a .NET Web Forms Views -> Razor converter on GitHub that looks like it would give you a good kickstart if you’re trying to switch over a project that you’ve already started.

Code clearly

December 6, 2010 § Leave a comment

I ran across a nice article just covering the basics of coding clearly. Since I’m currently spending most of my time correcting mistakes like this, I thought it worth a mention.

http://fob.po8.org/student-code

Free programming books

December 5, 2010 § Leave a comment

Need something to read? Check out this list of freely available programming books.

What’s in what, now?

December 1, 2010 § Leave a comment

I’ve been working with a client that is working on an Oracle to SQL Server conversion project, and part of it involves poring over stored procedures to fix inefficiencies. This type of thing keeps coming up, and since this isn’t the only client I’ve seen it at…

This is slow and inefficient:
SELECT @var1 = tab1.col2
FROM tab1
WHERE tab1.col1 =
  (
    SELECT tab2.col2
    FROM tab2
    WHERE tab2.col1 =
    (
      SELECT tab3.col2
      FROM tab3
      WHERE tab3.col1 = @par1
    )
  )

This is better and much, much faster:
SELECT @var1 = tab1.col2
FROM tab1
INNER JOIN tab2
  ON tab1.col1 = tab2.col2
INNER JOIN tab3
  ON tab2.col1 = tab3.col2
WHERE tab3.col1 = @par1

Where Am I?

You are currently browsing the Programming category at Mike Vallotton's Blog.