Archive for the ‘C#’ Category

Get list of WinForms Controls from an assembly

Here is the sample code.

private void ShowControlsFromAssembly(string assemblyfile)
{
Assembly assembly = Assembly.LoadFrom(assemblyfile);
Type[] et = assembly.GetExportedTypes();
[...]

Leave a Comment

ASP.NET - Download as ZIP

DotNetZipLib is one of the best compression/zip libraries for dotnet I found. You can download it from CodePlex.
Here is a snippet which demonstrates how to use DotNetZipLib to zip and force download directly to browser.

ZipFile zip = new ZipFile();
 
// Add files to zip
zip.AddFile(@"C:\blah.jpg", string.Empty);
zip.AddFile(@"C:\blee.jpg", string.Empty);
 
// save to memory stream instead of a direct file
MemoryStream ms [...]

Leave a Comment

Return DataTable from Web Service

I know this is an old theme but I had to write a sample app for demonstration in a tech forum. So reproducing here also.
Importantly, the DataTable/DataSet must be serializable.
ASMX Code:

public class Service1 : System.Web.Services.WebService
{
 
[WebMethod]
[...]

Leave a Comment

c# Listbox – change color of items

Again old theme but seems still people want this. Here is the code for doing this:

private void Form1_Load(object sender, EventArgs e)
{
listBox1.DataSource = new
string[] { "asdfljk", "sdfgsdfg", "xcv", "wrwerwer" };
[...]

Leave a Comment

Internet connection system tray notifier

Here is a tool for you to check if internet connection available or not. The tool uses below code for connection detection:
Download URL: http://kidoos.net/media/p/598.aspx

private bool IsInternetAvailable()
{
bool ret = false;
 
[...]

Comments (2)

C# CopyFromScreen Animation

Here is a code snippet:

private void Form1_Load(object sender, EventArgs e)
{
this.Show();
Graphics myGraphics = this.CreateGraphics();
 
[...]

Leave a Comment

Winforms Calendar code – C#

Here is a quick windows forms calendar code.
I used a TableLayoutPanel with Dock=Fill.

private void FillDays()
{
DateTime FirstDay = new DateTime(DateTime.Now.Year,
DateTime.Now.Month, 1);
 
int [...]

Leave a Comment

Get currently logged in user from a service running under LocalSystem account

Here goes the sample code:

using System.IO;
using System.Management;
using System.ServiceProcess;
 
namespace MyTestService
{
public partial class MyTestService : ServiceBase
{
public MyTestService()
{
InitializeComponent();
[...]

Leave a Comment

MS SQL Tables Viewer

This is one of my hobby tool which simply connects to a MS SQL Server database and shows all the available tables and its column names. This tool is programmed with Visual C# 2008 Express Edition.
Download from here: http://kidoos.net/media/p/588.aspx
Let me know if somebody needs source code. I have no plans to extend this app [...]

Leave a Comment

Populate listbox in a thread in .net

An old topic but still developers asking me same… so a blog.
If you try to use a textbox or any other control in side a thread, you will get an error like this:
Cross-thread operation not valid: Control ‘textBox1′ accessed from a thread other than the thread it was created on.
To avoid that, you need [...]

Leave a Comment