Thursday, June 12, 2008

SafeFileName Property and .Net 2.0 SP1

I built a small utility using C# Dot Net version 2.0 in which I took help of Open File Dialog box windows control to know user selected file path and name. I used “SafeFileName”(Gets a string that only contains the filename for the selected file.) property of OpenFileDialog box to display selected filename on the windows form. I did a fine testing on my development machine and deployed it on production computer. The production computer was up by freshly installed Windows Vista operating system (without SP1 update). since Vista ships with DotNet runtime, my job was as easy as copying my dot net executable assembly and double clicking it. When the OpenFileDialog box tried supplying user selected file name through “SafeFileName” property, it crashed! Damn...!!

The error message was clearly telling me that “method not found: OpenFileDailog.get_SafeFileName()”!! I was darn surprised. Though I did a quick fix for this problem by making use of FileName property (Gets or sets a string containing the full path of the file selected in a file dialog.), with little string manipulation to extract filename from complete file path and got the required result, the unsupported property error on Vista machine continued interrupting my thoughts. I did not see any documentation or remarks giving specific attention to this issue anywhere in Microsoft's official web space. When I installed Dot Net 2.0 SP1 (on production computer) and run my utility (without FileName property fix). This time there is no “method not found” error! The .Net 2.0 SP1 has fix for it though there is no specific note on this in Microsoft’s support knowledge base article
This experience taught me that, Before I go ahead copy my any 2.0 framework based dot net utility and run on any computer, make sure machine has got .Net 2.0 SP1 update or not.

No comments: