Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Wednesday, July 6, 2011

Developing Android applications using .Net

For long time i believed that i can not develop android applications using .Net but recently i found tutorial link on twitter which surprised me .
click here to open the tutorial .

Tuesday, January 26, 2010

.Net Coding Best Practices

Every one knows that follow the code best practices will prevent time wasting in code maintaining and will reduce the headache that the next developer will have during maintaining code and will improve performance of application.

I do some Google and collect some links for you:

.Net Coding Stranded : click here
ADO.Net Best Practices : Follow this article click here
.Net Performance Best practices : Follow this
click here
ASP.Net Best Practices: Follow this click here , here
, here
Exception Handling : follow this article click here
SQL Server : Follow this click here , here , here

I hope that this links help every one trying to code better.

Tuesday, August 4, 2009

Changing Table Schema – what goes behind the scenes – Part I - SQLServerCentral

interesting topic from SQL Server Central newsletter:
Changing Table Schema – what goes behind the scenes – Part I - SQLServerCentral

Tuesday, June 23, 2009

Differences between SET and SELECT in SQL Server

Always when we find two ways to do the same thing .we begin to think why,which is best and which is more suitable for me .i found something interested about the difference between Set and Select when we assign value to SQL variable . follow this link:
Differences between SET and SELECT in SQL Server : Narayana Vyas Kondreddi's home page

Wednesday, April 16, 2008

Cosmos what`s next ?

In the previous days i found something really good on codeplex.com , it is new open source project called "Cosmos" this project depend on running Microsoft intermediate language without operating system (it creates real time kernel) , this means you can run your c# program just by booting from CD
i`ll let you see the project page and read documentation , please follow this link

http://www.codeplex.com/Cosmos

Recently , i know that this project showed in Microsoft EDC (Egyptian Developer Conference) but i did not have the chance to attend to the conference , you can wait until the videos of the conference be available and i`ll paste a link here for this session

this is another resources and examples :

http://gocosmos.org/
http://www.gocosmos.org/Docs/UserKit/index.en.aspx
http://lab.obsethryl.eu/content/cosmos-one-opensource-csharp-c-based-kernels

Wednesday, March 19, 2008

Change MDI Container Background Color

MdiClient ctlMDI;

// Loop through all of the form's controls looking
// for the control of type MdiClient.
foreach (Control ctl in this.Controls)
{

try
{
// Attempt to cast the control to type MdiClient.
ctlMDI = (MdiClient)ctl;

// Set the BackColor of the MdiClient control.
ctlMDI.BackColor = this.BackColor;
}
catch (InvalidCastException)
{
// Catch and ignore the error if casting failed.
}

}

Sunday, March 9, 2008

Collection of WCF Sessions

This is a collection of videos i found through youtupe, i hope that this videos be useful for someone.

http://www.youtube.com/view_play_list?p=2471E942C68A6925

Source profile here

Saturday, March 8, 2008

Creating a simple user interface with MonoDevelop

I watched this video on Youtube , and i really like it - Can we make good C# applications without errors of visual studio , moreover on Linux .


Sunday, March 2, 2008

C# and .Net on Linux

another article talking about Compile and run C# command line and GUI applications on Linux by Shekhar Govindarajan

Click here to read

Saturday, March 1, 2008

Mono brings .NET apps to Linux

Mono, the open source development platform based on .NET, lets you build powerful, flexible Linux® applications and still take advantage of cross-platform capabilities using a variety of .NET-compatible languages. This article walks you through installing Mono on your system and developing your first sample Mono-compiled C# application that runs on both Linux and Microsoft ® Windows®.

Click to read article

Wednesday, February 6, 2008

Extract Tables from HTML page and store it in data set using Regular Expressions

Some times we need to extract information from HTML pages ,for example extracting table from HTML page
here you will find how to do it using regular expression , this code is written using C# :

private static DataSet ConvertHTMLTablesToDataSet(string HTML)
{
DataTable dt;
DataSet ds = new DataSet();
dt = new DataTable();
string TableExpression = "<table[^>]*>(.*?)</table>";
string HeaderExpression = "<th[^>]*>(.*?)</th>";
string RowExpression = "<tr[^>]*>(.*?)</tr>";
string ColumnExpression = "<td[^>]*>(.*?)</td>";
bool HeadersExist = false;
int iCurrentColumn = 0;
int iCurrentRow = 0;

MatchCollection Tables = Regex.Matches(HTML,
TableExpression,
RegexOptions.Singleline |
RegexOptions.Multiline |
RegexOptions.IgnoreCase);


foreach (Match Table in Tables)
{
iCurrentRow = 0;
HeadersExist = false;
dt = new DataTable();

if (Table.Value.Contains("<th"))
{
HeadersExist = true;

MatchCollection Headers = Regex.Matches(Table.Value,
HeaderExpression,
RegexOptions.Singleline |
RegexOptions.Multiline |
RegexOptions.IgnoreCase);

foreach (Match Header in Headers)
{
dt.Columns.Add(Header.Groups[1].ToString());
}

}
else
{

int myvar2222 = Regex.Matches(
Regex.Matches(
Regex.Matches(
Table.Value,
TableExpression,
RegexOptions.Singleline
| RegexOptions.Multiline |
RegexOptions.IgnoreCase)[0].ToString(),
RowExpression, RegexOptions.Singleline |
RegexOptions.Multiline |
RegexOptions.IgnoreCase)[0].ToString(),
ColumnExpression,
RegexOptions.Singleline |
RegexOptions.Multiline |
RegexOptions.IgnoreCase).Count;

for (int iColumns = 1; iColumns <= myvar2222; iColumns++)
{
dt.Columns.Add("Column " + System.Convert.ToString(iColumns));
}

}

MatchCollection Rows = Regex.Matches(Table.Value,
RowExpression,
RegexOptions.Singleline |
RegexOptions.Multiline | RegexOptions.IgnoreCase);

foreach (Match Row in Rows)
{

if (!((iCurrentRow == 0) & HeadersExist))
{
DataRow dr = dt.NewRow();
iCurrentColumn = 0;

MatchCollection Columns = Regex.Matches(Row.Value,
ColumnExpression,
RegexOptions.Singleline |
RegexOptions.Multiline |
RegexOptions.IgnoreCase);

foreach (Match Column in Columns)
{
dr[iCurrentColumn] = Column.Groups[1].ToString();
iCurrentColumn++;
}

dt.Rows.Add(dr);
}
iCurrentRow++;
}
ds.Tables.Add(dt);

}

return ds;
}

This code i found it through google but i converted it it C# ...
kick it on DotNetKicks.com

Friday, February 1, 2008

Validate Input Using Regular Expressions

Problem :
You need to validate that user input or data read from a file has the expected structure and content.
For example, you want to ensure that a user enters a valid IP address, telephone number, or e-mail
address.
Solution :
Use regular expressions to ensure that the input data follows the correct structure and contains only
valid characters for the expected type of information.
How It Works :
When a user inputs data to your application or your application reads data from a file, it’s good
practice to assume that the data is bad until you have verified its accuracy. One common validation
requirement is to ensure that data entries such as e-mail addresses, telephone numbers, and credit
card numbers follow the pattern and content constraints expected of such data. Obviously, you cannot
be sure the actual data entered is valid until you use it, and you cannot compare it against values that are known to be correct. However, ensuring the data has the correct structure and content is
a good first step to determining whether the input is accurate. Regular expressions provide an excellent
mechanism for evaluating strings for the presence of patterns, and you can use this to your
advantage when validating input data.
The first thing you must do is figure out the regular expression syntax that will correctly match
the structure and content of data you are trying to validate. This is by far the most difficult aspect of
using regular expressions. Many resources exist to help you with regular expressions, such as
The Regulator (http://regex.osherove.com/) and RegExDesigner.NET by Chris Sells http://www.sellsbrothers.com/tools/#regexd). The RegExLib.com web site (http://www.regxlib.com/) also provides hundreds of useful prebuilt expressions.
Regular expressions are constructed from two types of elements: literals and metacharacters.
Literals represent specific characters that appear in the pattern you want to match. Metacharacters
provide support for wildcard matching, ranges, grouping, repetition, conditionals, and other control
mechanisms. Table 2-2 describes some of the more commonly used regular expression metacharacter
elements. (Consult the .NET SDK documentation for a full description of regular expressions.)

Input Type Description Regular Expression
Numeric input The input consists of one or more decimal digits; for example,
5 or 5683874674.


^\d+$
Personal identification number (PIN)


The input consists of four decimal ^\d{4}$
Credit card number The input consists of data that matches the pattern of most major
credit card numbers; for example,
4921835221552042 or
4921-8352-2155-2042.


^\d{4}-?\d{4}-?\d{4}-?\d{4}$
Simple password

The input consists of six to eight characters; for example, ghtd6f
or b8c7hogh.

^\w{6,8}$
E-mail address

The input consists of an Internet expression
indicates that each address element
must consist of one or more word
characters or hyphens; for example,
somebody@company.com.

^[\w-]+@([\w-]+\.)+[\w-]+$
HTTP or HTTPS URL The input consists of an HTTP-based or HTTPS-based URL; for example, www.hotmail.com


^https?://([\w-]+\.)+[\w-]+(/[\w-./?%=]*)?$

The Code :
The ValidateInput method shown in the following example tests any input string to see if it
matches a specified regular expression.

using System;
using System.Text.RegularExpressions;

namespace mahmoud_alam
{
class new292
{
public static bool ValidateInput(string regex, string input)
{
// Create a new Regex based on the specified regular expression.
Regex r = new Regex(regex);
// Test if the specified input matches the regular expression.
return r.IsMatch(input);
}

public static void Main(string[] args)
{
// Test the input from the command line. The first argument is the
// regular expression, and the second is the input.
Console.WriteLine("Regular Expression: {0}", args[0]);
Console.WriteLine("Input: {0}", args[1]);
Console.WriteLine("Valid = {0}", ValidateInput(args[0], args[1]));
// Wait to continue.
Console.WriteLine("\nMain method complete. Press Enter");
Console.ReadLine();
}
}
}