The path is not of a legal form – error
If you are developing in Win Forms, and you are using some thirdparty controls like “Infragistics”, while taking the design some times you will get this error.
To resolve this issue
- Re-build the whole project, and try again.
- Check all the reference(s) are valid or not
Best of Luck
Display Please Wait While the Page Refreshes
While uploading large files, it is nice to have a “Please wait…” text displaying on the button. You can simple achive this using ClientScript.GetPostBackEventReference method.
this.uxUpload.Attributes.Add("onclick", "this.value='Uploading... please wait'; this.disabled=true;" + ClientScript.GetPostBackEventReference(this.uxUpload,""));
The GetPostBackEventReference injects the __doPostBack method and also the hidden fields that hold the event target and event arguments.
This is a useful technique when uploading large files and during the process disabling the button control.
Optional parameters in C#
If you are used VB 6.0 or VB.Net, and now using C# you will miss a nice feature of VB, optional parameters. The work around for optional parameters in C# is overloading the function. But you can also achive the same using “Params” key word.
Example : public void ExecuteNonQuery(string Query, params SqlParameter[] Parameters), you can call this function simply using Query parameter only.
Note : Anything after params keyword, takes as an argument, so we need to keep the params keyword as the last item in the argument list.
Last day and first day of the month using C#
Today while idling, I thought of developing a time tracker / personal job scheduler using ASP.Net. Initially I planned to use Asp.Net Calendar control, and after some time I thought of developing a calendar using C#. So I started coding but there is not simple function available in C# to find the first day of the month. After some googling I found a simple solution to get the first day.
DateTime firstDay = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
And for getting the Last day, I used the following functions.
int DaysinMonth = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
DateTime lastDay = firstDay.AddDays(DaysinMonth);
DateTime lastDay = firstDay.AddDays(DaysinMonth - 1);
DateTime lastDayOfMonth = firstDayOfMonth.AddMonths(1).AddTicks(-1); // Thanks to Holf ![]()
I am adding the same code in VB.Net too.
Dim firstDay As New DateTime(DateTime.Now.Year, DateTime.Now.Month, 1)
Dim DaysinMonth As Integer = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month)
Dim lastDay As DateTime = firstDay.AddDays(DaysinMonth - 1)
Happy coding