Skip to content

Archive

Archive for October, 2009

Create new class its name to GetInstance and write this below code on GetInstance class.

using System.Data.Sql;
using System.Collections;
using System.Data;

namespace SqlServer
{
    public class GetInstance
    {
        public static ArrayList GetInstanceName()
        {
            try
            {
                SqlServerList SqlSL = new SqlServerList();
                SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;
                DataTable table = instance.GetDataSources();
                ArrayList list = new ArrayList();
                foreach (DataRow row in table.Rows)
                {
                    SqlSL = new SqlServerList();
                    SqlSL.ServerName = row[0].ToString();
                    SqlSL.InstanceName = row[1].ToString();
                    SqlSL.IsClustered = row[2].ToString();
                    SqlSL.Version = row[3].ToString();
                    list.Add(SqlSL);
                }
                return list;
            }
            catch
            {
                return null;
            }
        }
    }
}

 

Create new class its name to SqlServerList and write this below code on SqlServerList class.
continue reading…

 Windows Media Encoder Desktop Experience Component Installed

 

To install the Windows Media Encoder Desktop Experience component by using the Windows Server 2008 Server Manager

  1. Click Start, click Administrative Tools, and then click Server Manager.
  2. In the left navigation pane, click Features, and then right click and select Add Features.
  3. On the Select Features pane, select the check box for Desktop Experience.
  4. Click Next from the Select Features pane, and then click Install at the Confirm Installations Selections pane.
  5. Click Close to leave the Add Features wizard.
  6. The server must be restarted for the changes to take effect.

continue reading…

Insert a PictureBox and change its name to ImageSource and write this below code on MouseMove event handler.

private void ImageSource_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left & ImageSource.Image != null)
            {

                ImageSource.DoDragDrop(ImageSource.Image, DragDropEffects.All);
            }
        }

Insert a PictureBox and change its name to ImageDest and write this below code on DragEnter event handler.
continue reading…

Import System.Text.RegularExpressions namespace.

using System.Text.RegularExpressions;
public bool IsEmailValid(string Address)
{
    string pattern = @"^(([^<>()[\]\\.,;:\s@""]+"
          + @"(\.[^<>()[\]\\.,;:\s@""]+)*)|("".+""))@"
          + @"((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
          + @"\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+"
          + @"[a-zA-Z]{2,}))$";
    Regex rest = new Regex(pattern);
    bool isrest Match = rest .IsMatch(Address);
    return isrest;
}

Sometimes we need to empty table.

DELETE FROM <TABLE name>

The following code to run on it:

DBCC CHECKIDENT (<TABLE name>, RESEED, 0)

You can use truncate table only if there are no contrains and foreign keys related with this table.

Import System namespace.

using System;

Convert Degrees To Radians

public static double CDTR(double degrees)
{
    return ((Math.PI / 180) * degrees);
}

Convert Radians To Degrees

public static double CRTD(double radians)
{
    return ((180 / Math.PI) * radians);
}

My answer about this question which , how you can clear all the text box inside a group panel

Answer:

private void cleartextboxes()
{
Control Alltext;
    foreach (Control tempLoop_Alltext in GroupBox1.Controls)
    {
      Alltext = tempLoop_Alltext;
      if (Alltext isTextBox)
         {
            alltext.Text = string.Empty;
         }
    }
}

Import System.IO namespace

using System.IO;

Create new class its name to CalculateDirectorySize and write this below code on CalculateDirectorySize class.

public long CalculateDirectorySize(DirectoryInfo directorypath, bool includeSubdirectories)
{
    long totalSize = 0;
    // Examine all contained files.
    FileInfo[] files = directory.GetFiles();
    foreach (FileInfo file in files)
    {
        totalSize += file.Length;
    }
    // Examine all contained directories.
    if (includeSubdirectories)
    {
        DirectoryInfo[] dirs = directorypath.GetDirectories();
        foreach (DirectoryInfo dir in dirs)
        {
            totalSize += CalculateDirectorySize(dir, true);
        }
    }
    return totalSize;
}

Add a Button and change its name to GetCalculate and write this below code on Click event handler.

private void GetCalculate_Click(object sender, EventArgs e)
{
    MessageBox.Show(CalculateDirectorySize(new DirectoryInfo( @"C:\WINDOWS"), true).ToString());
}

Import System.Drawing.Text namespace

using System.Drawing.Text;

Add a DropDownList and change its name to ListAllFont and write this below code on Form’s load event handler.

private void Form1_Load (object sender, System.EventArgs e)
{
InstalledFontCollection fonts = new InstalledFontCollection();
foreach (FontFamily font in fonts.Families)
    //ListAllFont is ListBox
    ListAllFont.Items.Add(font.Name);
}

String Manipulation in C#

Oct 15
Uncategorized

Trim Function
The trim function has three variations Trim, TrimStart and TrimEnd. The first example show how to use the Trim(). It strips all white spaces from both the start and end of the string.

//STRIPS WHITE SPACES FROM BOTH START + FINSIHE
string Name = " String Manipulation " ;
string NewName = Name.Trim();
//ADD BRACKET SO YOU CAN SEE TRIM HAS WORKED
MessageBox.Show("["+ NewName + "]");

continue reading…

Slider by webdesign