December 14th, 2009
wiley
How to display current row number in report view table.
An expression containing the RowNumber function, when used in a text box within a data region, displays the row number for each instance of the text box in which the expression appears. This function can be useful to number rows in a table.
=RowNumber(Nothing)

Unique visitors to post:
28
November 12th, 2009
wiley
TextBox.SelectionStart = 5;
This set caret position on TextBox to 5 char.

Unique visitors to post:
39
If you are working within a form you can use this to find it:
if (this.ActiveControl.Equals(testControl)
{
//......
}

Unique visitors to post:
6
C# how to obtain current direntory of the executing process:
System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
[/c-sharp]

Unique visitors to post:
0
A method to programaticaly opening folder with explorer:
string folderToOpen = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\archive";
string windir = Environment.GetEnvironmentVariable("SystemRoot");
System.Diagnostics.Process proccess = new System.Diagnostics.Process();
proccess.StartInfo.FileName = windir + @"\explorer.exe";
proccess.StartInfo.Arguments = folderToOpen;
proccess.Start();
[/c-sharp]
String variable folderToOpen contains path to “archive” folder under this folder in which the program works.
proccess.StartInfo.FileName contains path to “windows explorep”.

Unique visitors to post:
0
A class to create ZIP file from another file.
This class uses the free C# ZIP library (http://www.icsharpcode.net/OpenSource/SharpZipLib/Download.aspx) is great for reading and creating ZIP files.
The parameter source is full path to source file.
The parameter destination is full path to destination result zip file.
using System;
using System.IO;
using ICSharpCode.SharpZipLib.Checksums;
using ICSharpCode.SharpZipLib.Zip;
namespace Tools
{
public class Zip
{
public static void create(string source, string destination, string comment)
{
Crc32 crc = new Crc32();
ZipOutputStream s = new ZipOutputStream(File.Create(@destination));
s.SetLevel(9); // 0 - store only to 9 - means best compression
FileStream fs = File.OpenRead(@source);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
ZipEntry entry = new ZipEntry(ZipEntry.CleanName(@source));
entry.DateTime = DateTime.Now;
entry.Comment = comment;
entry.ZipFileIndex = 1;
entry.Size = fs.Length;
fs.Close();
crc.Reset();
crc.Update(buffer);
entry.Crc = crc.Value;
s.PutNextEntry(entry);
s.Write(buffer, 0, buffer.Length);
s.Finish();
s.Close();
}
}
}

Unique visitors to post:
4
A function to executing the batch file from C#
The value of the first argument [batchFileName] is full path to batch file.
The value of the second argument [argumentsToBatchFile] is array of argument if exist, sending to batch file.
protected bool ExecuteBatchFile(string batchFileName, string[] argumentsToBatchFile)
{
string argumentsString = string.Empty;
try
{
if (argumentsToBatchFile != null)
{
for (int count = 0; count < argumentsToBatchFile.Length; count++)
{
argumentsString += " ";
argumentsString += argumentsToBatchFile[count];
}
}
System.Diagnostics.ProcessStartInfo DBProcessStartInfo = new System.Diagnostics.ProcessStartInfo(batchFileName, argumentsString);
DBProcessStartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
DBProcessStartInfo.UseShellExecute = true;
System.Diagnostics.Process dbProcess;
dbProcess = System.Diagnostics.Process.Start(DBProcessStartInfo);
while (!dbProcess.HasExited)
dbProcess.WaitForExit(2000);
return true;
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
return false;
}
}

Unique visitors to post:
2
How to find IP address and Host name of computer running a program of C #.
Get Host name:
String strHostName ="";
// Get the host name of local machine.
strHostName = Dns.GetHostName();
Get IP addresses:
IPHostEntry ipEntry = DNS.GetHostByName(strHostName);
IPAddress [] addr = ipEntry.AddressList;
for (int i = 0; i > addr.Length; i++)
{
MessageBox.show("IP Address " + i.ToString() + ": " + addr[i].ToString());
}

Unique visitors to post:
222
Small example of how we can load DisplayMember and ValueMember in ComboBox Items.
1. Create a class, which will contain objects that will put in the items.
public class AddDuration
{
private string duration_Display;
private long duration_Value;
public AddDuration(string Display, int Value)
{
duration_Display = Display;
duration_Value = Value;
}
public string Display
{
get { return duration_Display; }
}
public long Value
{
get { return duration_Value; }
}
}
2. Here the function to load data CoboBox.
private void FormActivator_Load(object sender, EventArgs e)
{
ArrayList durations = new ArrayList();
durations.Add(new AddDuration("1 година", 1));
durations.Add(new AddDuration("2 години", 2));
durations.Add(new AddDuration("3 години", 3));
durations.Add(new AddDuration("4 години", 4));
durations.Add(new AddDuration("5 години", 5));
this.cbDuration.DataSource = durations;
this.cbDuration.DisplayMember = "Display";
this.cbDuration.ValueMember = "Value";
}
Line 10 shows what string is displayed in the ComboBox.
Line 11 shows, which will return value from the ComboBox.

Unique visitors to post:
6