Just a quickie then - needed to add something to the GAC on a server that didn't have the .NET 2.0 SDK installed. Didn't want to download 350Mb of the SDK just for a small tool - and found that most of the links for the .NET 2.0 SDK are actually broken, as if the entire thing has vanished from Microsoft's servers, or are hosted on other download sites.
Found a very useful blog post and tool on Aaron Stebner's WebLog - Details about setup for the .NET Framework 2.0 configuration tool, where he gives more information on this elusive configuration tool and even provides a handy little download and installer, clocking in at under 1Mb. Much better.
Friday, August 17, 2012
The simple art of making Json work in Internet Explorer
A couple of projects I've been working on - both for my day job, and for my personal site - utilise ASP.NET MVC, jQuery and Json. My prior development was using exclusively ASP.NET AJAX and, before that, plain old PHP, so when I discovered the three technologies above, I've not really understood why web development was ever any other way.
I primarily develop in Google Chrome - I used to use FireFox and Firebug, but found that Chrome's included Developer Tools are as good as - possibly better than - Firebug, particularly the Network monitor. The organisation I work in only supports Internet Explorer, but that would only affect the layout and styling, right? Once I've got the page looking right, I wouldn't need to check the actual functionality when it comes to Json data.
I couldn't have been more wrong. Although the site worked fine in Internet Explorer, posting data back to the database, and the updated information would even show in Chrome, IE just refused to show what had changed. So I dusted off the F12 Developer Tools in Internet Explorer - extremely difficult to do after using Chrome's Development Tools - and started to diagnose.
The first step I took was to open the Json request in a new IE tab. This wouldn't work. Instead of showing the raw Json data as I'd expect, it would attempt to download a file. I didn't want this, and for a while, thought this might be the cause of all my problems.
I did some research, and the ever-useful stackoverflow gave me the answer - I had to change every return Json command in my Controller to explicitly specify a MIME type. I shouldn't have expected Internet Explorer to figure it out for itself, like Chrome does. This link - IE9 JSON Data “do you want to open or save this file” - gave me the following answer:
Splendid - IE doesn't insist on downloading this file now, and will show the raw Json data instead. But looking at the data returned, I didn't see an error that would cause the data displayed on my actual page to be out of date - I used a simple "return Json(DateTime.Now ... )" test and this showed the correct time, down to the second.
So I continued my search for a solution to my second problem, and found another post - Unexpected Caching of AJAX results in IE8 - that indicated Internet Explorer forcibly caches AJAX requests. Although the request appears in the Network monitor, the data it uses is out of date. Adding the following line to my jQuery code resolves everything:
I'm glad I've managed to solve this issue, but I must admit, it's taken some of the fun out of developing. Everything was going so smoothly with MVC, Json, etc., until I discovered how antiquated and difficult Internet Explorer still is to this day. Why is it so strict with MIME types? Why is it automatically caching dynamic data? And, of course, why does it interpret CSS so differently to other browsers?
And I suppose the ultimate question (or answer) is, why do Microsoft have to run an advertising campaign to convince people to use a free browser that is, let's face it, still included in Windows by default?
Rant over. Moving on.
I primarily develop in Google Chrome - I used to use FireFox and Firebug, but found that Chrome's included Developer Tools are as good as - possibly better than - Firebug, particularly the Network monitor. The organisation I work in only supports Internet Explorer, but that would only affect the layout and styling, right? Once I've got the page looking right, I wouldn't need to check the actual functionality when it comes to Json data.
I couldn't have been more wrong. Although the site worked fine in Internet Explorer, posting data back to the database, and the updated information would even show in Chrome, IE just refused to show what had changed. So I dusted off the F12 Developer Tools in Internet Explorer - extremely difficult to do after using Chrome's Development Tools - and started to diagnose.
The first step I took was to open the Json request in a new IE tab. This wouldn't work. Instead of showing the raw Json data as I'd expect, it would attempt to download a file. I didn't want this, and for a while, thought this might be the cause of all my problems.
I did some research, and the ever-useful stackoverflow gave me the answer - I had to change every return Json command in my Controller to explicitly specify a MIME type. I shouldn't have expected Internet Explorer to figure it out for itself, like Chrome does. This link - IE9 JSON Data “do you want to open or save this file” - gave me the following answer:
return Json(someData, "text/html", System.Text.Encoding.UTF8,
JsonRequestBehavior.AllowGet);
Splendid - IE doesn't insist on downloading this file now, and will show the raw Json data instead. But looking at the data returned, I didn't see an error that would cause the data displayed on my actual page to be out of date - I used a simple "return Json(DateTime.Now ... )" test and this showed the correct time, down to the second.
So I continued my search for a solution to my second problem, and found another post - Unexpected Caching of AJAX results in IE8 - that indicated Internet Explorer forcibly caches AJAX requests. Although the request appears in the Network monitor, the data it uses is out of date. Adding the following line to my jQuery code resolves everything:
$.ajaxSetup({
cache: false
});
I'm glad I've managed to solve this issue, but I must admit, it's taken some of the fun out of developing. Everything was going so smoothly with MVC, Json, etc., until I discovered how antiquated and difficult Internet Explorer still is to this day. Why is it so strict with MIME types? Why is it automatically caching dynamic data? And, of course, why does it interpret CSS so differently to other browsers?
And I suppose the ultimate question (or answer) is, why do Microsoft have to run an advertising campaign to convince people to use a free browser that is, let's face it, still included in Windows by default?
Rant over. Moving on.
Thursday, August 9, 2012
Getting the current user's domain + account name in MVC 3
Quick and easy one (now that I've found it out) - prior to using MVC 3, I was using User.Identity.Name to get the current user's name. But since moving to MVC 3, that property was returning blank.
Discovered the correct way to do this is simply:
Environment.UserDomainName + "\\" + Environment.UserName
This will happily return DOMAIN\accountname. Easy when you know how...
Discovered the correct way to do this is simply:
Environment.UserDomainName + "\\" + Environment.UserName
This will happily return DOMAIN\accountname. Easy when you know how...
Thursday, August 2, 2012
Silverlight appears on top of pop-up menu
The SharePoint site I'm working on features a top navigation bar that drops down a submenu when the main menu buttons are hovered over. There's nothing particularly clever going on there - it uses jQuery, and is tied in with the standard SharePoint navigation.
However, a few pages on the site have a Silverlight object at the top of the editable page - so, directly underneath the top navigation bar. On these pages, the Silverlight object would appear to be always on top, so the pop-up element would always appear behind it. This means that you couldn't navigate to other areas of the site.
I found a fix on the Silverlight forums that consisted of two parts:
However, a few pages on the site have a Silverlight object at the top of the editable page - so, directly underneath the top navigation bar. On these pages, the Silverlight object would appear to be always on top, so the pop-up element would always appear behind it. This means that you couldn't navigate to other areas of the site.
I found a fix on the Silverlight forums that consisted of two parts:
- For the DIV that contains the Silverlight object, position: absolute is required.
- For the Silverlight object, an additional param is required: windowless should be set to true, like this: <param name="Windowless" value="true"/>
Problem solved, like magic.
Friday, July 27, 2012
Triggering a workflow when expiry date is approaching
Out of the box, SharePoint allows workflows or tasks to begin when a certain date is reached. However, there's nothing that will trigger a workflow when a date is approaching. For example, I have a list of contracts that have expiry dates attached in a custom column. I want an expiry notification to fire three months before that date.
I found a solution here - Item expiration reminders in SharePoint using workflow - but for some reason, the workflow didn't work as expected, possibly due to the structure of my data. So I've made some changes, trimmed it a little, and present it below.
Only one additional column had to be created - named "Previous due date", it's a date column in which the workflow stores the current expiry date. It may even be possible to remove this column entirely, but I've left it in to make it easier to check the progress of the workflow.
What the workflow does is: it stores a workflow variable called Alert Date, which is simply three months before the Expiration Date. If the Expiration Date is after today, it will set the new column, "Previous due date", to the current Expiration Date, and also sets a workflow variable, "Original Due Date", to the Expiration Date. It will then carry out two actions in parellel -
I found a solution here - Item expiration reminders in SharePoint using workflow - but for some reason, the workflow didn't work as expected, possibly due to the structure of my data. So I've made some changes, trimmed it a little, and present it below.
Only one additional column had to be created - named "Previous due date", it's a date column in which the workflow stores the current expiry date. It may even be possible to remove this column entirely, but I've left it in to make it easier to check the progress of the workflow.
What the workflow does is: it stores a workflow variable called Alert Date, which is simply three months before the Expiration Date. If the Expiration Date is after today, it will set the new column, "Previous due date", to the current Expiration Date, and also sets a workflow variable, "Original Due Date", to the Expiration Date. It will then carry out two actions in parellel -
- Wait for the Alert Date to be reached, and then send an email
- Wait for the Expiration Date in the item to change, and then stop the workflow.
Since the workflow runs on change or create, we don't want the same workflow running multiple times on the same item because the item has been changed, so the second action takes care of that.
Here's the actual workflow:
Different views inside a document set
I have a site which has a large list of Document Sets, one for each customer. These document sets are grouped by their country. However, when opening the document set, the contents are also grouped by country, because by default, a document set uses the same view, and it's not smart enough to realise the grouping is for the document set, not the contents.
Easy solution I've just discovered (thanks to this blog post) -
Easy solution I've just discovered (thanks to this blog post) -
- Create a new view, based on the original view, but without the Grouping
- Open the Library Settings, and select the Data Set from under Content Types
- Select Document Set Settings.
- Scroll down until you find the Welcome Page View setting - you can change the view here.
Thursday, July 12, 2012
SharePoint Lookup with Picker
A site I'm working on has a very long lookup list. SharePoint 2010, by standard, only allows a dropdown for this, and that's just insane when you have thousands of items to choose from. So I found the iLove SharePoint Lookup Field with Picker 2010 which allows the user to use something similar to the people picker, but with lookup entries. Extremely useful and works perfectly, except...
The site uses Word templates, and the templates use SharePoint properties. I'm getting some strange behaviour when using the Lookup Field with Picker: namely it's not possible to change the lookup value from Word. I only get a single option - "1" - and two blank options. When selecting the blank option, the "1" option vanishes from the document properties.
I'm now trying to find a way to display a dialog when the document is first created in SharePoint that forces the user to pick a selection from the lookup, and then not allow that selection to change.
The site uses Word templates, and the templates use SharePoint properties. I'm getting some strange behaviour when using the Lookup Field with Picker: namely it's not possible to change the lookup value from Word. I only get a single option - "1" - and two blank options. When selecting the blank option, the "1" option vanishes from the document properties.
I'm now trying to find a way to display a dialog when the document is first created in SharePoint that forces the user to pick a selection from the lookup, and then not allow that selection to change.
Subscribe to:
Posts (Atom)
