Parameter Name asp.net 4.0 New feature

25. June 2010

Another new feature in 4.O FrameWork, Name Parameter,Let see in the Below Sample how to pass the parameter.

 

protected void Page_Load(object sender, EventArgs e)
   {
   	foreach (int i in Add( n1:20,n2:60))
   	{
   		Response.Write(i.ToString() + " ");
   	}
   }
  

 public static IEnumerable Add(int n1, int n2)
 {
 
 return i*i;
 
 }


Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

ALL, asp.net, asp.net 4.0, CSharp ,

encrypting and decrypting function using Csharp

11. February 2010

Author : Aamir Hasan 
Below is the given code how to encrypt and decrypt the data

public class Encryption_Decryption
{
const char CharacterToFill = '@';
static string Key = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

public string EnCrypt(string str)
{
int count;
int ctr;
int size = str.Length;
string R = "";

for (count = 0; count < size; ++count)
{
ctr = (str[count] >> 2) & 0x3f;
R += Key[ctr];
ctr = (str[count] << 4) & 0x3f;
if (++count < size)
ctr |= (str[count] >> 4) & 0x0f;

R += Key[ctr];
if (count < size)
{
ctr = (str[count] << 2) & 0x3f;
if (++count < size)
ctr |= (str[count] >> 6) & 0x03;

R += Key[ctr];
}
else
{
++count;
R += CharacterToFill;
}

if (count < size)
{
ctr = str[count] & 0x3f;
R += Key[ctr];
}
else
{
R += CharacterToFill;
}
}

return (R);
}

public string DeCrypt(string str)
{
string R = "";
int count;
char ctr;
char ctrNext;
int size = str.Length;

for (count = 0; count < size; ++count)
{
ctr = (char)Key.IndexOf(str[count]);
++count;
ctrNext = (char)Key.IndexOf(str[count]);
ctr = ((char)((ctr << 2) | ((ctrNext >> 4) & 0x3)));
R += ctr;
if (++count < size)
{
ctr = str[count];
if (CharacterToFill == ctr)
break;

ctr = (char)Key.IndexOf(ctr);
ctrNext = (char)(((ctrNext << 4) & 0xf0) | ((ctr >> 2) & 0xf));
R += ctrNext;
}

if (++count < size)
{
ctrNext = str[count];
if (CharacterToFill == ctrNext)
break;

ctrNext = (char)Key.IndexOf(ctrNext);
ctr = (char)(((ctr << 6) & 0xc0) | ctrNext);
R += ctr;
}
}
return (R);
}
}

 

.


Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

ALL, asp.net, CSharp , ,

Capturing Web Camera and Microphone using Silver

4. February 2010

Author : Aamir Hasan

This is my first tutorial on silverlight.In this article i am going tell you how to utilize a user's web camera and microphone attached to their computer via the browser, to capturing audio and video.


First you have to add namespace in your cs file as given below

using System.Windows.Media;
using System.Windows.Media.Imaging;


ObservableCollection images adding images to it:

CaptureSource _captureSource;
ObservableCollection<WriteableBitmap> _images = new ObservableCollection<WriteableBitmap>();

Caturing the video


  

if (_captureSource != null)
{
_captureSource.Stop(); // stop whatever device may be capturing

// set the devices for the capture source
_captureSource.VideoCaptureDevice = (VideoCaptureDevice)VideoSources.SelectedItem;
_captureSource.AudioCaptureDevice = (AudioCaptureDevice)AudioSources.SelectedItem;

// create the brush
VideoBrush vidBrush = new VideoBrush();
vidBrush.SetSource(_captureSource);
WebcamCapture.Fill = vidBrush; // paint the brush on the rectangle

// request user permission and display the capture
if (CaptureDeviceConfiguration.AllowedDeviceAccess || CaptureDeviceConfiguration.RequestDeviceAccess())
{
_captureSource.Start();
}
}

 

Create a Snapshot from the Video


When the capture process has started and a user clicks the Take Snapshot button, the appropriate command is invoked in the VM and the capture source’s AsyncCaptureImage method is invoked. I used the Dispatcher to make sure I operated on the UI thread because I wanted to not only grab the bitmap.


 

private void StopCapture_Click(object sender, RoutedEventArgs e)
{
if (_captureSource != null)
{
_captureSource.Stop();
}
}

private void TakeSnapshot_Click(object sender, RoutedEventArgs e)
{
if (_captureSource != null)
{
// capture the current frame and add it to our observable collection
_captureSource.AsyncCaptureImage((snapImage) =>
{
_images.Add(snapImage);
});
}
}


 


Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

ALL, CSharp ,

Find Out Specific File Extensions In a Root Directory

4. January 2010

String[] files = Directory.GetFiles("", "*.xls");
int totalCount = files.Length;
int count;
foreach (String fileName in files)
{
if (GetSheetName(fileName).Equals("your value"))
count++;
}

private String GetSheetName(String fileName)
{
string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;"
+ @"Data Source=" + fileName + @";Extended Properties=""Excel 12.0;HDR=YES;""";

OleDbConnection connection = new OleDbConnection(connectionString);
connection.Open();
String sheetName = this.GetSheetName(connection.GetSchema("columns"));
return sheetName;
}



To Find out the files in a root here i have given example of Excel files
Regards
Aamir Hasan


Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

ALL, asp.net, CSharp , ,

Bulk Copy From Datatable To SQL Server Table

1. January 2010

 public bool BulkEnterData(DataTable dt, string tblName)
    {
        SqlBulkCopy bulk = new SqlBulkCopy(con);
        bulk.DestinationTableName = tblName;
       
        con.Open();
        bulk.WriteToServer(dt);
        con.Close();

        return true;
    }

 

 

to run sqlbulkcopy u must define listed below if it give u an error {A transport-level error has occurred when receiving results from the server. (provider: Shared Memory Provider, error: 0 - The pipe has been ended.)}

Go to Start -> Programs -> Microsoft SQL Server 2005 -> Configuration Tools -> SQL Server Surface Area Configuration.

 

Then go to "Surface Area Configuration for Services and Connections"

 

Then select "Remote Connections" under "Database Engine" option.

 

Then select "Using both TCP/IP and named pipes" radio button under Local and remote connections.


Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

ALL, CSharp, SQL 2005 & 2008 , , ,



User Name: Guest

Your Ip: 38.107.191.90
Time: