Tuesday, May 26, 2009

JavaScript Finally Gets Red Carpet Treatment

Visual Studio 2010 – you complete me.

In addition to the well advertised javascript intellisense (no longer a meager add in) and jQuery integration, I read something today that is further evidence  of JavaScript’s “here to stay (so you better get on board)” status: The JavaScript profiling features built in to Visual Studio 2010. Read more about it here on the VS Profiler Team Blog:  http://blogs.msdn.com/profiler/archive/2009/04/21/website-performance-talk-at-mix09.aspx

Can’t wait for Visual Studio 2010? You can get the predecessor to this feature today in the form of the VS 2008 AJAX Profiling Extensions. Soma Somasegar’s blog has a good post on this: http://blogs.msdn.com/somasegar/archive/2009/04/29/vs2008-ajax-profiling-extensions.aspx

What is cool is that there are no client requirements for all of this – JavaScript is modified on the fly from the server to include instrumentation that captures the performance data. This may sound a little redundant if you are familiar with the profiling features built in to the latest browsers/add-on’s, like IE8’s profiler or FireBug. These are great tools, but I think making a browser-independent ‘tool’ is almost more useful, since in general if you are using IE8 or FireFox with FireBug installed, you are probably NOT experiencing performance problems! I see a particular value here in determining the delta between antique browsers and those who stay reasonably current with technology. That is another way of saying this will help U.S. gov’ment users still using IE6, as most of them still are.

I may experiment with this in the near future and post my results. If there’s time.

Monday, May 18, 2009

Setting AfterProperties in Event Receiver

They just couldn’t be the same.

I needed to capture the current date and user when a field was changed. So in the event receiver’s ItemAdding event, I thought I would set the AfterProperties the same way you would normally set an item’s field value:

properties.AfterProperties[userField] = user;
properties.AfterProperties[dateField]
= DateTime.Now;


No dice: Error on both lines of code. So how to set them? To find out I set the fields manually and examined the AfterProperties during the event receiver’s invocation. Here is what I found:



A SPUser field is not an SPUser in the AfterProperties dictionary, it is the SPUser.ID converted to a string. And why wouldn’t it be…



A DateTime field is also a string, except not just a string produced by the DateTime.ToX functions – since that would be too logical. The DateTime AfterProperty is actually a string produced by the SPUtility.CreateISO8601DateTimeFromSystemDateTime method. No – I did not make that up – it is very real. So I guess DateTime in AfterProperties goes all international on you, since that is what that naming convention implies. (see here)



SO here is the working code that captures user and current datetime in the AfterProperties:



properties.AfterProperties[userField] = user.ID.ToString();
properties.AfterProperties[dateField]
= SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.Now);
Thursday, May 14, 2009

Setting ContentType of SPListItem

The ContentType property of a SPListItem is readonly. Yet the SharePoint UI lets you change it. So how to change it? This guy beat me to it and has two nice methods that accomplish this should-be-simple-but-yet-again-not-obvious task:

Alexander B's Blog

SPSaturday DC Presentations

Non-biased opinion: Some great presentations here:

SharePoint Saturday DC Resources

Wednesday, May 13, 2009

SPListItem will not update

Not even close to a record – second “easy thing that eats up a few hours”.

The situation: Simple postback event handler that updates a field in a list to a new value. Here is the code:

protected void DenyRequest( object sender, EventArgs e )
{
    try
    {
        Item[fieldname] = RequestStatus.Denied;
                
        Item.Update();
        RedirectToPreviousPage();
    }
    catch (Exception ex)
    {
        errorLabel.Text = string.Format("Sorry, there was an unexpected error: {0}", ex.Message);
    }
}


The issue: The field value never changes! The line of code gives no indication of failure – the update also succeeds – but the value never freakin changed.



The solution I found to by way of this dude’s blog: Nick Grattan Blog Post who needed to get a new reference to the item to have it change the value. So the working code looks like this:



protected void DenyRequest( object sender, EventArgs e )
{
    try
    {
        SPListItem item = List.GetItemById(Convert.ToInt32(ItemID));
        item[fieldname] = RequestStatus.Denied;
        item.Update();
        RedirectToPreviousPage();
    }
    catch (Exception ex)
    {
        errorLabel.Text = string.Format("Sorry, there was an unexpected error: {0}", ex.Message);
    }
}


So the difference was that before the Item was a property that returned the list item using the GetItemById method using the same ItemID property, and now that is done inline with the update code. Is it just me, or should the code work either way? What is the difference if you have a property that returns the item or get the item inline with the update?!



Oh, SharePoint Object Model, you’ve done it again!

SharePoint Retract|Deploy|Annoy

Problem:

Solution redeployment kept failing from STSDEV project. So I headed into central admin – status was deployed. Retracting had no effect – solution status still said deployed! So then I took a look at what exactly it was deployed to. It was the central admin site. Went to try to retract one more time, but this time instead of selecting ‘all content urls’ I intended to select the CA url. One problem: it was not in the drop down list. Annoyance complete.

Solution:

Had to run a command line with the specific CA url:

"C:\Program Files\Common Files\Microsoft
Shared\web server extensions\12\bin\stsadm.exe" -o retractsolution -name MySolution.wsp -immediate -url http://mossCA

 

 
© I caught you a delicious bass.
Back to top