Michael Olivero
The official blog of Michael Olivero, Software Architect & Humble Entrepreneur

.NET Framework FileInfo.Delete() method throws UnauthorizedAccessException

Thursday, 1 March 2012 17:03 by Michael Olivero

When deleting a file using FileInfo.Delete() method, the .NET framework sometimes throws an exception as shown below:


Yet, when you delete the file manually through explorer its removed fine from the filesystem.  At first I though this was a glitch of some type because the program runs with my login credentials much like the local logged in user credentials applies to windows explorer.  It turns out if the file is marked as ReadOnly it also throws this exception.  Changing the attributes prior to deleting will automatically resolve this problem.

An additional note, since this program was working with a directory where files were continually being created and removed, there was an additional observation with the File.CreationTime.  In very few cases when iterating through the files in the directory, the CreationTime would show a date time value of 1/1/1600 despite the file already existing.  I attribute this to simply a race condition where the FileInfo.CreationTime of my program gets to the file just before the actual creation date of the file is set by the operating system. This would need to be validated as I would expect the creation time of the file to be set in an atomic way along with the file creation.

Tags:   ,
Categories:   Software
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed

Windows 8 and HTML5 is this a deja vu of the 90's and Visual Java?

Friday, 9 September 2011 20:30 by Michael Olivero

A few weeks ago I read about Microsoft making Windows 8 UI and platform based on HTML5.  Meaning, developers should adopt towards HTML5 over say the previous product they were pushing really hard - silverlight.  This about face has a very interesting parallel to the past which I will digress into shortly.


Silverlight was destined to be the solution to all the deficiencies of developing within the stateless http applications.  The technology embraced the best features of existing technologies unifying them with a serious amount of innovation into a mature platform many developers swore as the future of web technology.  It is declarative using XML (XAML to be specific), it has a rich presentation similar to flash but much better as it was SEO friendly among other things, it is a runtime which is cross platform so Linux users just as much as Windows users would be able to run these apps with the same consistency as Adobe Flash today.  They even borrowed the best from their own .NET platform and cherry picked the essential APIs (to keep the runtime as small as possible).

So, with all this innovation and push towards silverlight, even including it as the basis for their new mobile platform, it's understandable developers are in uproar as to why Windows 8 will move towards HTML5 instead.

A few hours ago, I came to a realization. I'm not second guessing Microsoft, but it sure feels like deja vu.

Back in 1996 or 1997, Microsoft created their first Visual Studio integrated product. They called it "The Year of the Developer" and I probably still have the nifty poster they included in the box somewhere.  In short, they decided to integrate all their development tools similar to how they integrated all their office products. The idea was simple and novel.  Sell the suite cheaper than the individual products and give a Word user a new application to play with (Excel).  The same applied to the development tools and both integrated suites were a phenomenal success -- and still are as we are still working with these integrated suites to this day.  As part of this integration, Microsoft included Java as a language to develop with and build a large class of libraries so Java could work with Windows (call this the precursor of .NET).  So this suite contained Visual Interdev, Visual C++, Visual Basic, and Visual Java.  

As we now know, a large legal battle with Sun eventually forced Microsoft to remove the Java name and instead change it to J#.  The core argument from Sun was very simple -- Microsoft cannot call it "Java" if it is not Java from all the Microsoft specific windows libraries.  By the time the settlement came around the damage was done.  Java was climbing up stream from an adoption perspective with development environments such as Eclipse either non-existing or nowhere near the maturity of Microsoft's development environments.  So with Microsoft's marketing muscle and center-of-attention position they had before, they were able to get a vast majority of developers to develop Java with Visual Java.  Why not right?  It had all the environment features were developers were used to such as intellisense, was binary compatible with Java so long as you didn't use Microsoft's extensions, etc.

Well, many already know the end of that story and transcripts of the various cases against Microsoft essentially shows Microsoft intentionally derailed the adoption of Java enough, keeping Visual Java stuck on Java 1.1 as declared by BillG himself in key emails, while they developed their response.  This put the breaks on the evolution of Java significantly, especially at a core juncture where Sun was pushing Java 1.2 with it's revised event model to better handle large scale applications.  Microsoft literally stole the spotlight using Visual Java and suite as a tool.  This derailment and time-buying was all Microsoft needed to build their version of the runtime -- calling it .NET.  To ensure they lure all their existing developers C++ and VB, their model was to have all languages compile to a common byte-code.  In this process, their new language, C#, very similar to Java, will take center stage in the new developer suite.

So how does all this relate to today?  Well, for quite some time Microsoft has been pushing silverlight.  Why the about face to HTML5 for Windows 8 if they have a great following and even included it for their new mobile phone platform?  I hope I'm wrong, but I feel it may be a repeat cycle of what occurred with Java.

Microsoft may see HTML5, the richest application framework-to-date for building desktop-like applications on the web, as a threat to their desktop dominance. Their celebratory sabbatical for winning the browser wars, with over 90% market share at peak, caused them to leave Internet Explorer in limbo on version 6 while the rest of the world was moving along with the evolving web standards.  They even moved the developers off Internet Explorer to the Windows group.  This allowed for a slow shift towards using standards based browsers with Firefox taking a decisive lead.  Following Firefox many others popped up -- including Apple with Safari and Google with Chrome utilizing rendering engines such as WebKit while others such as Opera built their own.  Developers started alienating Internet Explorer by building sites with the emerging standards -- after all standards worked with all browsers and for the most part, so long as it it's not too fancy, worked with Internet Explorer too.  If we fast forward to today, Internet Explorer is actually behind in market share in Europe and has lost significant market share domestically as well.

So it's clear to me, either two things are happening with Microsoft and HTML5.  Either Microsoft it truly adopting standards and making genuine strides in interoperability with other technologies and platforms like Linux and even building it into their next Windows or they are simply attempting another coup.

I shared this with a friend and colleague via text (I'm not sure if he wants me to publish his name so I blurred it out), but he always has a valid opinion on matters and his response was decisive.  There were four consecutive texts; each with more emphasis than the previous so he clearly sees it as possibly a deja vu.

Only time will tell where the truth lies.