Posts Tagged: .Net 4.0

How to apply border color for TableLayoutPanel

Posted by & filed under .Net, .Net 4.0, Windows Forms.

The TableLayoutPanel control arranges its contents in a grid. TableLayoutPanel doesn’t have border color property, but you can write custom code in CellPaint event to create border. Here is the code snippet which will help you to create border and apply color for TableLayoutPanel Here is the screen shot of the Form in Design Time [...]

Using SynchronizationContext in Windows Forms

Posted by & filed under .Net, .Net 3.0 / 3.5, CodeProject, Windows Forms.

Long back I wrote a post about how to fix – System.InvalidOperationException – Cross-thread operation not valid exception, while we try to access user interface elements from a different thread, other than the thread(normally main thread), which created the user interface elements. .NET 2.0 brings us SynchoronizationContext which allows us to execute a section of [...]

How to upload file to FTP server using C#

Posted by & filed under .Net, .Net 3.0 / 3.5, .Net 4.0, Windows Forms.

From .net framework 2.0 onwards .net supports FTP operations. Like HttpWebRequest and HttpWebResponse, for FTP operations, FtpWebRequest and FtpWebResponse classes are available, under System.Net namespace. Here is the code snippet, which will help you to upload a file to FTP server, using C#. And here is the GetFileData function, which will return byte array from [...]

How to create controls dynamically in asp.net and retrieve values from it

Posted by & filed under .Net, .Net 3.0 / 3.5, .Net 4.0, ASP.Net, CodeProject.

Sometimes you may require to create controls dynamically in asp.net. Because of asp.net page life cycle, you may loss the created controls on next post back(ASP.Net framework recreate the page on postback). You can resolve this issue by overriding LoadViewState() and SaveViewState() methods. LoadViewState() method restores view-state information from a previous page request that was [...]

How to return value based on condition in Moq

Posted by & filed under .Net, .Net 4.0, Miscellaneous, Unit Testing.

Today I while writing unit test for one class I got a problem, I have factory method, which will return values based on the input given, and I want to mock this method. I was using Moq for mocking. And I found a solution like this. Happy Programming