C#

Encription of user sensitive data

Posted on December 19, 2008. Filed under: C# |

using System;
using System.Collections.Generic;
using System.Text;
/// <summary>
/// Summary description for Base64
/// </summary>
public sealed class Base64
{
public static string Encode(string data)
{
try
{
byte[] encData_byte = new byte[data.Length];
encData_byte = Encoding.UTF8.GetBytes(data);
string encodedData = Convert.ToBase64String(encData_byte);
return encodedData;
}
catch(Exception e)
{
throw new Exception(“Error in base64Encode ” + e.Message);
}
}
public static string Decode(string data)
{
try
{
UTF8Encoding encoder = new UTF8Encoding();
Decoder utf8Decode = encoder.GetDecoder();
byte[] todecode_byte = Convert.FromBase64String(data);
int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
char[] decoded_char [...]

Read Full Post | Make a Comment ( None so far )

keyword searching result from database in C#

Posted on May 23, 2008. Filed under: C# |

public static DataSet RelatedKeyword(string keyword)
{string[] arr =keyword.Replace(“& “,“”).Split(‘ ‘);
DataSet ds = new DataSet();
DataSet dsTemp = new DataSet();
bool flag = false;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["remote"].ConnectionString);
// DBAccess db = new DBAccess();
SqlDataAdapter sda;
foreach (string s in arr)
{ if (s.Length >= 2)
{ sda = new SqlDataAdapter(“select distinct top 60 keywordid, keywordname from keyword  where keywordname like ‘%’+@ksearch+’%’”, con);
sda.SelectCommand.Parameters.Add(“@ksearch”, SqlDbType.VarChar).Value = [...]

Read Full Post | Make a Comment ( None so far )

Sending mail in asp.net

Posted on May 12, 2008. Filed under: C# |

System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.From=new MailAddress(“mymail@gmail.com”);
mail.To.Add(new MailAddress(“sendmail@yahoo.com”));//enter company name which send
mail.IsBodyHtml=true;
mail.Subject = “Sending Enquiry”;
mail.Body = “Enquiry About Company “;
//Proper Authentication Details need to be passed when sending email from gmail
System.Net.NetworkCredential mailAuthentication = new
System.Net.NetworkCredential(“maymail@gmail.com”, “password”);
//Smtp Mail server of Gmail is “smpt.gmail.com” and it uses port no. 587
//For different server like yahoo this details changes and you [...]

Read Full Post | Make a Comment ( 1 so far )

Creating Datalayer in Class file

Posted on May 12, 2008. Filed under: C# |

using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace DATAACCESS.SQL
{
public class DATALAYER:IDisposable
{
private IDbCommand cmd=new SqlCommand();
private string strConnectionString=””;
private bool handleErrors=false;
private string strLastError=””;
public DATALAYER()
{
ConnectionStringSettings objConnectionStringSettings = ConfigurationManager.ConnectionStrings["connect"];
strConnectionString = objConnectionStringSettings.ConnectionString;
SqlConnection cnn=new SqlConnection();
cnn.ConnectionString=strConnectionString;
cmd.Connection=cnn;
cmd.CommandType = CommandType.StoredProcedure;
}
public IDataReader ExecuteReader()
{ IDataReader reader=null;
try
{
this.Open();
reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
}
catch (Exception ex)
{
if (handleErrors)
strLastError = ex.Message;
else
throw;
}
return reader;
}
public IDataReader ExecuteReader(string commandtext)
{
IDataReader reader=null;
try
{
cmd.CommandText=commandtext;
reader=this.ExecuteReader();
}
catch(Exception ex)
{
if(handleErrors)
strLastError=ex.Message;
else
throw;
}
return reader;
}
public object ExecuteScalar()
{
object obj = null;
try
{ this.Open();
obj = cmd.ExecuteScalar();
this.Close();
}
catch [...]

Read Full Post | Make a Comment ( None so far )

Recursively find control from previous page

Posted on April 9, 2008. Filed under: C# |

hi
i study more time asp.net starter kit and i found best code for finding previous page server control.
But from prevoius page you must use  postbackurl on button  or use  server.transfer(“go.aspx”);
The code is follow……..
public sealed class Util{ 

 
private Util(){
}
 

 
public static Control FindControlRecursively(string controlID, ControlCollection controls){
if (controlID == null || controls == null) 

 
return null; 
 
foreach (Control c in controls){
 
 
if [...]

Read Full Post | Make a Comment ( None so far )

    About

    Hi,I am Suresh Sharma from Gorakhpur , UP, India.I have work on .net technology from 2 years. Key skills-Asp.net 2.0,3.5, Sql 2005,2000. Ajax.net 1.1,C#.net

    RSS

    Subscribe Via RSS

    • Subscribe with Bloglines
    • Add your feed to Newsburst from CNET News.com
    • Subscribe in Google Reader
    • Add to My Yahoo!
    • Subscribe in NewsGator Online
    • The latest comments to all posts in RSS
    • Subscribe in Rojo

    Meta

Liked it here?
Why not try sites on the blogroll...