Print This Post

SharePoint Quick Surveys 1.0.5 and catching up…

It’s been a while since I’ve posted on this blog. There’s been a lot going on around here so I’ve not really had the time to devote to it. There have been loads of comments posted. Many of the queries I’ve answered by email but I thought it might be useful to answer the most frequently asked questions here.

Quick Surveys bug

A number of people have pointed out a small bug in the Quick Surveys web part. Basically what happens is that some people get prompted to re-enter the survey answers again after submission rather that getting the graphical results displayed. A couple of people have very kindly posted with a solution to the issue which is to change line 129 in QuickSurvey.cs from:


author = SPContext.Current.Web.CurrentUser.LoginName;

to


author = SPContext.Current.Web.CurrentUser.Name;

Now this does work but it’s not the complete solution. In a survey list SharePoint stores the person who created the response in the Author field of the list item. This is stored something like the following 16;#Darren Johnstone where the first part is the user’s ID number and the second part is the user’s display name. The original bug in Quick Surveys existed because the query used to determine if a user had already responded was checking against the login name.

This means that changing the query to use the SPContext.Current.Web.CurrentUser.Name property (i.e. the display name) as suggested by people will fix the issue. However, it also means that people with the same display name will not be able to submit responses to the same survey if multiple responses are not allowed. What we really need to do is query by the ID of the user instead (SPContext.Current.Web.CurrentUser.ID). To allow this we also need to set a LookupId='TRUE' attribute in the Author FieldRef of the query. This allows querying by the user’s ID and changes the AlreadyResponded method to:

/// <summary>
/// Determines if the user has already responded to this survey.
/// </summary>
/// <returns>True if the user has already responded.</returns>
bool AlreadyResponded()
{
    SPQuery query = new SPQuery();
    query.Query = String.Format("<Where><Eq><FieldRef Name='Author' LookupId='TRUE'/><Value Type='User'>{0}</Value></Eq></Where>", SPContext.Current.Web.CurrentUser.ID.ToString());

    return (theList.GetItems(query).Count > 0);
}

I’ve made this change in version 1.0.5 of the feature which is in the downloads section.

I’ve also been asked if it would be possible to limit the total number of responses to a survey. This could be accomplished by creating a new property (MaximumResponses) of type integer. The AlreadyResponded method could then be changed like this:

/// <summary>
/// Determines if the user has already responded to this survey.
/// </summary>
/// <returns>True if the user has already responded.</returns>
bool AlreadyResponded()
{
    SPQuery query = new SPQuery();

    // Check for maximum responses
    if (theList.ItemCount >= MaximumResponses) return true;
    // ----

    query.Query = String.Format("<Where><Eq><FieldRef Name='Author' LookupId='TRUE'/><Value Type='User'>{0}</Value></Eq></Where>", SPContext.Current.Web.CurrentUser.ID.ToString());

    return (theList.GetItems(query).Count > 0);
}

This will cause any user above the threshold to be presented with the results graph straight away.

ASP.Net file upload MVC compatibility

I’ve had a few emails asking about a version of the ASP.Net file upload module which works with ASP.Net MVC. I’m looking at this just now and will hopefully be able to add the appropriate helper methods into a new release shortly. I’m really impressed with ASP.Net MVC and am looking forward to the final release.

Travelling Blogger

A lot of people have emailed saying that they are using Travelling Blogger and like it. However, some are having issues using it on different types of mobile device. I developed the software on a WM6 Pro emulator and use it on an HTC phone. I don’t have the resources to test on all types of different phone but I’m intending to release the source code shortly so that people can at least amend it themselves. I’ll probably do this at the same time as adding in the much requested (and sadly lacking- sorry) copy and paste feature.

Post a Response