Kill A Certain Process in TaskManager using C#
Precondition:
I have many processes that I can view on my Task Manager.
Then I want to kill Process that run the Microsoft Word Application.
How to view your Task Manager:
Just right click on your Taskbar and click Task Manager.
It will appear that Microsoft Word’s process’s name is “WinWord.exe”
So to kill it just apply, these code:
Process[] pros = Process.GetProcesses();
for (int i = 0; i < pros.Count(); i++)
{
if (pros[i].ProcessName.ToLower().Contains("winword"))
{
pros[i].Kill();
}
}
That’s a wrap.
Convert a File into a Byte of Array
Precondition:
There are 2 examples that I describe in this post. First, is convert a file to a byte of array using BinaryFormatter and the second is using File.ReadAllBytes.
Example 1:
Using BinaryFormatter
I make a function that receive the address of the file and return a bye of array
function byte[] ConvertFileToByteArray_1 (string path)
{
BinaryFormatter bf = new BinaryFormatter();
MemoryStream msx = new MemoryStream();
bf.Serialize(msx, path);
msx.Seek(0, 0);
byte[] sender= msx.ToArray();
msx.Close();
return sender;
}
Example 2:
Using File.ReadAllBytes
I make a function that receive the address of the file and return a bye of array
function byte[] ConvertFileToByteArray_2 (string path)
{
byte[] sender= File.ReadAllBytes(path);
return sender;
}
Further explanation:
these are the value of functions’ parameter can be processed:
string path = string.Format(@"C:\Documents and Settings\xxx\Desktop\xxxx.htm");
or
string path= string.Format("{0}\\{1}.htm",directory, xxxx"));
where directory can be written like this above
string directory = string.Format("C:\\Documents and Settings\\xxx\\Desktop");
The path above means that xxx is your current System User and the xxxx is your file’s name. The htm is an ordinary extension, you can replace it by pdf or doc or something else, just based on your needs.
And don’t forget to give security to your file.
My suggestion is just add user ‘Everyone’ and ‘Full Control’ permission.
Convert Byte of Array into Object
Precondition :
I want to convert byte of array into a Object.
Description:
I want to build a function that receive a byte of array parameter and return an object.
Code:
function Object ConvertByteArrayToObject (byte[] receiver)
{
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
ms.Write(receiver, 0, receiver.Length);
ms.Seek(0, 0);
Object _sender= bf.Deserialize(ms);
ms.Close();
}
Using Stream Reader and Stream Writer (C#)
Example using Stream Reader
string File = Server.MapPath("/test/test.html");
StreamReader sr = new StreamReader(File);
string sreader = sr.ReadToEnd();
sr.Close();
Explanation :
It used to read string until the end of file test.html in a virtual directory “/test/test.html”
Example using Stream Writer
string directory = "C:\\Documents and Settings\\riani\\Desktop\\TESPDF\\TESPDF\\TESPDF\\test";
StreamWriter sWriter = File.CreateText(directory + "\\name.html");
sWriter.Write(sreader);
sWriter.Close();
Explanation :
It used to write string, which result of stream reader before, to a new created file at the certain directory and a file named as name.html.
Notice that after finished using both streams, don’t forget to close it.
Windows Command Line in C#
Precondition :
I want to run a command line like picture below

so here a bar of code that can be used:
string directory = "C:\\Documents and Settings\\riani\\Desktop\\TESPDF\\TESPDF\\TESPDF\\test";
System.Diagnostics.Process Process = new System.Diagnostics.Process();
Process.StartInfo.FileName = directory+ "\\ghtmldoc.exe";
Process.StartInfo.Arguments = "--webpage -f "+ "test.pdf " + " test.html";
Process.StartInfo.WorkingDirectory = directory;
Process.Start();
or
string directory = "C:\\Documents and Settings\\riani\\Desktop\\TESPDF\\TESPDF\\TESPDF\\test";
System.Diagnostics.ProcessStartInfo processStartInfo = new System.Diagnostics.ProcessStartInfo();
processStartInfo.FileName = directory+ "\\ghtmldoc.exe";
processStartInfo.Arguments = "--webpage -f "+ "test.pdf " + " test.html";
Process.Start(startInfo);
Easy as it seen…
‘ETIMEDOUT’ : undeclared identifer
Problem:
error C2065 : ‘ETIMEDOUT’ : undeclared identifer
Precondition:
Using HTMLDOC via Visual C++ then build it then come up the problem above
Solution :
Because I am using WINDOWS SERVER 2003, ETIMEDOUT is unknown.
So I replace the ETIMEDOUT with WSAETIMEDOUT
It also happen if we used ECONNREFUSED.
In Windows, it known as WSACONNREFUSED.
The End.
Download Youtube Part 3
Another fool of me…
Recently I had been told that there are another web that provided us a service to download youtube…
Here are the webs that my friend told me
http://www.youddl.com/
http://javimoya.com/blog/youtube_en.php
The mechanism is similar with the old ones that had discussed at
http://maroonluph.wordpress.com/2009/04/20/download-youtube/
the difference is that the source of url. You can’t longer get it at inside the web but you copy it from your browser address url.
So now there are two alternatives to download youtube as written at
http://maroonluph.wordpress.com/2010/06/22/download-youtube-part-2/
and
with using two webs that I wrote above.
Nice huh?
World is even prettier… cos downloading youtube has become easier…