New tutorial for C# about using XML data in a DataSet object for manipulating the data like it came from a database. See the Software Development section, or go straight to it here. Cheers, and happy coding!
Archive for the ‘C#’ Category
Tutorial: .NET XML Into A DataSet
Tags: C#, Development, Tutorial
Posted in C#, Development | Comments (0)
Beep on the Enter Key
One of the applications that I wrote and maintain here for use at my job is a C# Windows application. A couple of revisions ago I set it up so that the user could press the Enter key to submit the login instead of having to click the actual login button. For the longest time now this has produced a beep sound. ANNOYING!
I finally took the time to address this. On the text boxes I was catching the KeyUp event and checking for the Enter key. Come to find out that to properly make sure that the WHOLE event gets handled I needed to use the KeyPress event, and set the Handled property to true so that it would not flow back down to the key event handler on the form. Now, no more beep!
Tags: C#, Development
Posted in C#, Development | Comments (0)
SyncXpress Update
Ladies and Gentlemen! I have put up for public download the first alpha release of SyncXpress. It is still in VERY early production, and not ready for prime time, so use at your own risk. You will need .NET 2.0 to run this application. I also hope to have a forum up soon for feedback and chat regarding features and bugs and such.
Posted in C#, Development | Comments (0)
Images in SQL
So I was presented with a task today of extracting images that were stored in a Microsoft SQL Server 2000 database and save them as JPEG files. Here is a bit of code that will do this. In this code sample I am assuming domain authenticated SQL login. The table name here will be called Photos and the column names id, type, and photo.
-
SqlConnection connection;
-
SqlCommand command;
-
SqlDataReader reader;
-
-
string outputDirectory = "C:\TestLocation";
-
-
using (connection = new SqlConnection("data source=MyServer;initial catalog=Database;persist security info=True;packet size=4096;Trusted_Connection=True"))
-
{
-
connection.Open();
-
-
command.CommandType = CommandType.Text;
-
command.CommandTimeout = 3000;
-
-
reader = command.ExecuteReader();
-
-
while (reader.Read())
-
{
-
try
-
{
-
byte[] rawBytes = (byte[]) reader["photo"];
-
memStream.Write(rawBytes, 0, rawBytes.Length);
-
-
string filename = outputDirectory + "\\image-" + reader["id"].ToString() + "-" + reader["type"].ToString() + ".jpg";
-
-
pic.Image = Image.FromStream(memStream);
-
pic.Image.Save(filename, System.Drawing.Imaging.ImageFormat.Jpeg);
-
-
memStream.Close();
-
}
-
catch (Exception ex)
-
{
-
}
-
}
-
}
This C# code will loop over a record set and save the images stored in the table as JPEG files. Happy coding!
Tags: C#, Development, SQL
Posted in C#, Development | Comments (0)
Logical Drives and WMI
In an effort to support removable media devices in SyncXpress I’ve had to do a bit of learning about WMI in .NET. It is actually quite cool how much information you can get from WMI about ANY piece of hardware attached to your system, and even INSIDE your system. So in my case I want to find out information about a logical drive device in Windows. Using the System.Management namespace we can access the ManagementObject classes that will allow us to query the WMI services to get information about our device. Here is an example of getting information about your C:\ drive.
-
ManagementObject wmi;
-
string serialNumber, name, freeSpace;
-
-
-
serialNumber = wmi["VolumeSerialNumber"].ToString();
-
name = wmi["Name"].ToString();
-
freeSpace = wmi["FreeSpace"].ToString();
For more information on what data can be queried on a logical device see http://msdn2.microsoft.com/en-us/library/aa394173.aspx
Tags: C#, Development
Posted in C#, Development | Comments (0)
SyncXpress
Long under development, and not due to complexity, has my program SyncXpress been. I am happy to state that it is nearly done with the first beta. I’ve got most all the interface elements built. Package management is working, allowing you to create, modify, and delete packages and their respective targets. I finished writing and testing the directory exclusion list editor last night, and it is working well. I then began on the actual synchronization process, and once that part is done, I’ll be ready to put it up for download as a beta.
The site to start looking at stuff: http://www.syncxpress.com
Posted in C#, Development | Comments (0)