Sunday, 17 July 2011

J-AXE: A File Splitter in C#

Introduction

 J-AXE file splitter is a windows application developed using C# .Net to split file in to time interval,Based on size and total files after splits. I would not ignore the fact that this is some kind of new application, Already there is so many open source project are available to achieve the same purpose. Then the question is why I have spent lots of time to develop this app: allow me to explain the question: whatever application is available as open and/or paid, you will not get the options to splits the file based on Time interval or duration. But here you will get this functionality along with other functionality with new flavor; and the main point is that I wanted to develop this using C#.Net and by developing this kind of application I will get a chance to learn something new And even I would utilize my free time into something productive .So I did this and here is the UI of this J-AXE file splitter application.
 (http://www.codeproject.com/KB/applications/JAXEFileSplitter.aspx)


                                                  Fig 1. JAXE File Splitter UI.


Might be you will think that why this application name is J-AXE? Actually the letter J came from Jawed and AXE is to cut some wooden block. So, I have chosen this application name as J-AXE.

Background

 Of course there was something which triggers me to come up with this ideas/application. Last month I recorded family videos using my camcorder after that I added few songs and effect in to recorded video to make it movies so that I can distribute this among family’s members. Now I wanted to split this file into durations instead of size so that I can make it into different parts, something like Part1 as 30 minutes and Part2 as45 Minutes. I searched here and there for open source but whatever I got all were having functionality to splits file only by size not by the time interval.

Then this requirement triggered some chemical imagination into my mind to come up with some application to fulfill my requirement and here it is an application “J-AXE: A file Splitter”.
 
Using the code

 J-AXE: A file Splitter a Windows application is very handy in use. The whole solution is divided into 2 Projects .One project would be User interface and Second Project would be nothing but our main logic which is in DLL format. The idea to separate logic from UI and make logic as DLL so, that anybody can use it easily without referring to my UI implementation.

Let me give you some pictorial presentation of the whole scenario (Class Diagram):
 
                                Fig 2. Class Diagram of JAXE File Splitter with JAXE DLL.


First I would like to explain the implementation of UI part. Then, I will explain the Logic part :

PART1: User Interface
The Block diagram would be something like this:

                                   Fig 3. Block Digaram of JAXE File Splitter.


On UI User will get below option to splits the file:
1. Based on Duration (Time duration in sec/min)
2. Size(in Bytes/KB/MB)
3. And Number of files

Based on the option selected we will call the corresponding function to splits the file:

I have already published this application on Code project., for code details and explanation you can visit the below link for the same:

J-AXE: A File Splitter in C# on Code project by Me. Jawed.

~jawed

Saturday, 9 July 2011

Move Items from one listbox to other list box

So,here is the piece of code for that:

public static void MoveSelItems(ListBox from, ListBox to)
{
for (var i = 0; i < from.SelectedItems.Count; i++)
{
to.Items.Add(from.SelectedItems[i].ToString());
from.Items.Remove(from.SelectedItems[i]);
}
}
~jawed

Splites files using C#

Here is the code snippet to Put files under AXE to splits the particular file and then place the output files at target location.

Using System.io;
Using System;

//Method to split files
public void SplitFileBasedOnNumberOfFiles(string inputFile, int noOfFiles,string outPutLocation)

{
//Open the file in read mode

var fs = new FileStream(inputFile, FileMode.Open, FileAccess.Read);
//read the inputs for how many files user want after splitting
var numberOfFiles = Convert.ToInt32(noOfFiles);
//get the size of each file after splitting
var sizeOfEachFile = (int)Math.Ceiling((double)fs.Length / numberOfFiles);
//start the for loop to go through num of file and split that
var baseFileName = Path.GetFileNameWithoutExtension(inputFile);
var extension = Path.GetExtension(inputFile);

for (var i = 1; i <= numberOfFiles; i++)
{
//get the base name
//get the extension of the file
//get the out put location with output file name
var outputFile = new FileStream(outPutLocation + "\\" + baseFileName + "_" + i.ToString().PadLeft(5, Convert.ToChar("0")) + extension, FileMode.Create, FileAccess.Write);
var bytesRead = 0;
//array of bytes
var buffer = new byte[sizeOfEachFile];
//read the file bytes by bytes and put into output buffer
if ((bytesRead = fs.Read(buffer, 0, sizeOfEachFile))
outputFile.Write(buffer, 0, bytesRead);
outputFile.Close();
}
fs.Close();
}


Print html or any files from Windows form using C#

Using this code you would be able to print any type of pages.
just copy and paste this code on any button event handler.

private void buttonPrint_Click(object sender, EventArgs e)
{
try
{
Process printProc = new Process();

 printProc.StartInfo.FileName =" yourFileName";
printProc.StartInfo.UseShellExecute = true;
printProc.StartInfo.Verb = "print";
printProc.StartInfo.CreateNoWindow = true;
printProc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
printProc.Start();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Jawed Blog say!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

}

Thanks,
Md. Jawed

Saturday, 5 March 2011

C# Code snippet to send an Email with attachment from Outlook, Yahoo, HotMail, AOL and Gmail

1. Down Load Source Code click here.
Introduction
Using this code snippet user would be able to send an email with attachment through Outlook, Yahoo, AOL, HOTMAIL and Gmail.
Background
Already loads of information are available on internet for the same purpose. But not all the code is placed at one place. So here is my small effort to accumulate all the code at one place and that is nothing better than CodeProject. Hopefully it will be helpful for the beginners or whoever in needs of it.
Using the code
Name Space:

Block Diagram(SMTP Setting for various client):
Below is the Block diagram for the SMTP settings i have used to send out an email from various client providers.
Wherever needed I have explain the code in details. The codes are self explanatory, any way for the same I have included comments. So here is the code snippet to achieve your purpose.
1. Using Outlook:
To send an email using outlook, we need to add a reference to the dynamic link library for Outlook which is called Microsoft.Office.Interop.Outlook.dll.
For the same follow the below steps
1. Go to your solution explorer
2. Click on add a reference
3. Click on .Net Tab
4. Go through the DLL and select Microsoft.Office.Interop.Outlook.dll correctly.
5. When you have selected the correct reference you select the “OK” button and this reference will be added to your project under references.

6. Now we need to add a reference in our class to the Outlook reference we have added to the project in our previous example.
using Outlook = Microsoft.Office.Interop.Outlook;
And finally the code would look something like this:

2. Using HOTMAIL:
To send an email using HotMail, we need to add a reference to the dynamic link library for Hotmail/Gmail/AOL/Yahoo which is called System.Net.Mail.
For the same follow the below steps:
1. Go to solution explorer of your project
2. Select add a reference
3. Click on .Net Tab
4. Go through the DLL and select System.Net.Mail.
5. When you have selected the correct reference you select the “OK” button and this reference will be added to your project under references.
6. Now we need to add a reference in our class to the Hotmail/gmail/aol/yahoo reference we have added to the project.
using System.Net.Mail;
Note: The HOTMAIL SMTP Server requires an encrypted connection (SSL) on port 25.
And finally the code would look something like this:

3. Using Yahoo! 4. Using AOL:
5. Using Gmail:
Note:
The GMAIL SMTP Server requires an encrypted connection (SSL) on port 487.




Already I am using the above code snippet for my automation purpose and its working fine for me!!

Thank you!!
Feel Free to provide your comments and suggestion.
Md. Jawed.