Tuple Type Added to C# 4.0

With C# 4.0 you can now use the new Tuple type instead of creating your very own… far simpler than using a struct or class to accomplish the same task.

There are two ways to create a Tuple in c# 4.0:

var newTuple = new Tuple<string, string, int>("Sean", "Jaeger", 36);
var newTuple = Tuple.Create<string, string, int>("Sean", "Jaeger", 36);


Type inference can also be used (but doesn’t self document):



var newTuple = new Tuple.Create("Sean", "Jaeger", 36);


You can add up to eight parameters now:



var newTuple = new Tuple<int, int, int, int, int, int, int, int>(1, 2, 3, 4, 5, 6, 7, 8);


One huge thing I see in using a Tuple rather than an anonymous type is the fact that scope can be at any level.  As we all know the scope of an anonymous type is limited to the method boundaries.



Fun stuff!

HtmlEncode() Without The HtmlEncode()

<script runat="server" language="c#">
  protected string BadHtml = "<script language='javascript'>alert('Hello');</script>";
</script>
<%=BadHtml%>


The code above would cause an alert box to pop saying “Hello” because it is not HTML encoded.  Typically what you might do here is use the Server.HtmlEncode() method within a property and use that instead.  But now with C# 4.0 & Visual Studio 2010 you can just write this:



<script runat="server" language="c#">
    protected string BadHtml = "<script language='javascript'>alert('Hello');</script>";
</script>
<%:BadHtml%>


Notice the “:” instead of “=”.  This will automatically do the encode for you.  Saving keystrokes is great!

10 Things That Frustrate Me – Part I

I decided that I need to break away from the geeky stuff and post something else.  Below is a list of things that frustrate me day-to-day.  Some are work related, other things are just the environment that we live in today…

  1. People who claim they know a lot more than they really do
  2. Drivers that drive less than the speed limit when the weather is perfect
  3. Pigeons – do I need to explain?
  4. 90 degree weather in April – Arizona was not the only place this year!
  5. People who come to a garage sale and offer $2 on an item marked $20 that is worth $50
  6. Having to press 2 for English… having to look for the English section on instructions… going to Wal-Mart and seeing everything written in Spanish… driving down I-17 and seeing all the billboards in Spanish… American schools teaching English as a SECOND language!!
  7. Most unions – Especially teachers unions…. one of many things destroying America’s education system
  8. Lotus Notes – only 9 steps to flag an email for follow-up, 4 to remove that flag.  What, search by email subject?  That’s silly…
  9. Taxes – we get taxed on the gas that fills the car that we got taxed on to get to work earning a paycheck that has taxes removed so we can pay for a house that gets taxed and to buy food that gets taxed… chewing gum that was taxed… watching cable TV that is taxed… using water that is taxed… electricity… just to die and have the money that we wish to leave to our children taxed.  I am surprised they have not found a way to tax the balance on revolving credit accounts!
  10. People who are afraid to be told they failed or did not do well or as well as others… I can write a book about this one!  Get over it!  America (and most of the world for that matter) was built on the many who failed and the few who succeeded.  We would not have the great technology and scientific knowledge we have today if it were not for those failures that motivated another to push forward.

SQL Reporting Services – Same Machine

A few days ago while in Greensboro, NC I ran into a few issues setting up SQL reporting services on the same machine that SQL Server 2008 is installed.  Apparently if you install SQL reporting services on the same machine as the SQL server running as a non-default instance  you need to first have the SQL Browser Service running.  You then need to configure reporting services to point to [servername]\[instancename].  Typically I would use [servername],[instanceport]… but that does not work!

Locking MOSS or WSS

Server or site migrations require that you give yourself ample time for the transition.  The last thing you want is for users to be making changes on the site while you are taking a backup and moving to another location.  There are many ways to avoid this server-side that will interrupt the users viewing experience.  But, there is one way that you can still allow the users to interact with the MOSS or WSS site without allowing them to add/update/delete content.  By using the site lock feature you can switch an entire site collection to read-only mode.

stsadm –o setsitelock –url http://server/site –lock { none | noadditions | readonly | noaccess }

none = sets site to “normal” mode allowing adds/edits/deletes

noadditions = no additional content can be added, current content can be edited as long as it doesn’t add to the total content

readonly = entire site becomes readonly.  No adds/updates/deletes are permitted

noaccess = locks total access from the site.  User will see an error specifying that they contact the administrator for more information

Failure Decompressing Data from a Cabinet File

The MOSS/WSS GUI is great for many of the day-to-day administrative tasks, but I have found that it falls short on many of the larger tasks such as migrating entire sites or even large lists.  Using the STSADM command line tool with the correct parameters can solve errors like the one in the title of this entry.

stsadm -o export -url http://server/site -includeusersecurity –nofilecompression -filename C:\directory
stsadm -o import -url http://server/site -includeusersecurity -nofilecompression -filename C:\directory

-includeusersecurity = will add ALL of the user accounts that have posted, edited, or have been given direct access to the site.  This can either be a great help or a major pain.  If the site and lists on the site rely heavily on tracking who created/modified files in document libraries, or you have workflows that use people pickers or utilize the createdby or modifiedby fields this should be included.

-nofilecompression = makes the export larger, but does not throw the failure decompressing error.  Using this flag also requires that you use the command line tool to import.

If either of these flags are included on the export, they will also need to be included on the import.

Another Custom Form Issue

After making a few changes to a custom form “NewForm_2.aspx” in WSS I realized that I needed to start over.  I deleted the form and copied “NewForm.aspx” again and renamed to “NewForm_2.aspx”.  When doing this you need to point WSS to the new form by using SharePoint Designer, right clicking the list, then using the “Supporting Files” tab browse to the newly created custom form:

image

image

The issue was when I deleted “NewForm_2.aspx” I broke the hook that WSS had to the form.  Even recreating the form did not reset the hook.  When clicking the “New” button on the list I got the error “Invalid Page URL:”.  Microsoft has a KB article on this:

http://support.microsoft.com/kb/935504

But that does not resolve the issue.  It states “To resolve this issue, delete the list, and then re-create it.”. This was not an option with a list with over 400 items and 50+ fields.  So I went on the hunt and finally found this article:

http://blogs.msdn.com/dszabo/archive/2007/02/20/custom-list-newform-aspx-ruined-in-wss-3-0.aspx

In the article they explain the issue and a few ways to resolve it without deleting the list and recreating.  The option that I found that worked was in the “POST-POST COMMENT: ALTERNATIVE RESOLUTION” section.  Here you just need to replace a piece of the HTML code used by WSS to build the page.  It worked like a charm!

SharePoint Custom Form Issue

A few days ago my boss and I were on a 4.5 hour call trying to fix a SharePoint custom list that had started behaving strange after a migration from MOSS to WSS.  The creator of the list customized the “NewForm.aspx” and named it “NewForm_2.aspx”.  The issue was a single column that was not saving when a new item was created, but could be edited and it would save fine.   It was a lookup column to a list on the same site that had about 25 items.

First, we recreated the column with a new name & copied the data over then deleted the old column.  I refreshed and reordered the SharePoint custom data list on “NewForm_2.aspx”.  Still not saving…

Second, we recreated the lookup list.  Still not saving…

Third, we changed the column to a standard choice control and hard-coded the values from the lookup list into the choice field.  Still no luck…

I would go into all that we did, but it might take a few hours to list… so after “NewForm_7.aspx” was created (2,3,4,5,6 failed) I decided to not rearrange the fields on the form, leave them as they were default.  It worked!  So I reordered the columns in the list settings and created “NewForm_8.aspx”.  All is good now.

Lesson of this story: When creating custom forms in SharePoint.  #1 do not delete the placeholder where the data control is.  #2 Do not move fields on the form.  Removing fields is OK, but once they are moved you get unpredictable results.  Use the list settings to reorder the columns how you want THEN create the form.