Skip to main content

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 http://support.microsoft.com/kb/945757
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.

Comments

Popular posts from this blog

Windows forgets visual effects settings on log-out or reboot for non-administrator account

Steps given here worked for me with Windows 7 SP1. Hope you may find it useful.

Start -> Run-> cmd (press enter) -> type SystemPropertiesPerformance.exeThis gets you the "System Properties" window, go to  Advanced tab -> Performance Settings -> Visual Effects tab and choose "Adjust for best performance" and click OK. Note: While doing all these UAC doesn't show-up as all changes you are doing will be saved in your logged-in profile account.

Reference material used: http://msdn.microsoft.com/en-us/library/ee330866.aspx

Feel free to comment your findings.

Why Akbar was Great?

I have fanatical interest to be acquainted with what made Indian emperors take influential decisions during their reign. Few great kings’ valuable decisions created a remarkable history.

When Akbar accepts the marriage proposal of Hindu King (Bharmal of Amer), he wishes to make an attempt to set an example for two culture and religions and convey the message of peace. Later, destiny takes him to the critical path of life having most depraved political and family oriented problems. Being a true great emperor, Akbar learns and conclude challenges by demonstrating his exceptional leadership qualities. With his verdicts, Akbar stands as an incomparable king of all time. “Jodha Akbar” – brings 16th-century incidents to life and shows beginning part of Akbar’s married life which was, in fact, a deal for political gain. This decision slowly unleashes Akbar’s loving life, internal dreadful politics, painfully desirous people around him and betraying family members.

Jalaluddin Mohammad Akbar is…

Hangfire with ASP.Net MVC : Simplest Code To Start with

It seems many are looking for using Hangfire with ASP.Net MVC 4 / 5+ SQL Server here is the simplest code example for you to start quick.

I am using Visual Studio 2017 Community Edition

1) Create ASP.Net MVC 4/5 Projects
2) <add key="owin:AutomaticAppStartup" value="false" /> in web.config file
3)Run Install-Package HangFire -Version 1.6.17 or visit here for latest version: https://www.nuget.org/packages/Hangfire/1.6.17
4) From the sample code, make sure you create database in SQL Server DB and update the connection string.
5) I am simply updating a table with a primary key (auto incremented), and string field "StampTime" with current date and time.
6) Open Global.asax.cs and put this code.
7) Run the app and check the database.

The example code also showcase a hack on how to run jobs with few seconds interval.

namespace HangFireDemo { publicstaticclassMyTasks { publicstaticasync Task<int> MinuteTick() { awa…