Sei sulla pagina 1di 10

A) Regular Expression:

1)Regular Expression for checking the range of password like between 4 to 10 chars and
should be only alphabets….

^[a-zA-Z'.\s]{4,10}$

B) Code for Sending E-Mail


protected void Button1_Click(object sender, EventArgs e)
{
MailMessage mail = new MailMessage();
mail.From = new MailAddress(TextBox2.Text);

mail.To.Add(TextBox1.Text);
mail.Subject = TextBox3.Text;

mail.Body = TextBox4.Text;

SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);


smtp.EnableSsl = true;

smtp.Credentials = new
NetworkCredential("dinniesuper@gmail.com", "1234");

try
{
smtp.Send(mail);
}
catch (SmtpException ex)
{
Label5.Text = ex.ToString();
Label5.Visible = true;
}
}

c) CSS Tutorial

www.w3schools.com/css/
D) Code to check how many times our site has been hit, or to check
site traffic
1)
<%@ Application Language="C#" %><script runat="server">
void Application_Start(object sender, EventArgs e)
{
Application["userCount"] = 0;
Application["usersOnline"] = 0;
}
void Session_Start(object sender, EventArgs e)
{
Session.Timeout = 20;Application.Lock();
Application["userCount"]=1+(int)Application["userCount"];
Session["someValue"] = Session.SessionID;
Application["usersOnline"] = (int)Application["usersOnline"] + 1;
Application.UnLock();
}
void Session_End(object sender, EventArgs e)
{
Application.Lock();
Application["usersOnline"] = (int)Application["usersOnline"] - 1;
Application.UnLock();
}

2)

The level of this code requires only a minimal amount of knowledge of the
.NET environment, and of course your website should be hosted on a
windows server with the .NET environment.

This code can be copied and pasted in the footer area of any .aspx file in
your website. Generally, you would put it in the footer of the home page,
or at least that's a good place to start.

The first thing you'll want to do is create an empty text file, call it
counter.txt and save it to your root directory. The next step is even easier,
copy and paste the code below into your .aspx file and save it. Be sure to
import the system.IO class into your page something like this

< script runat="server" >


public string counter()
{

StreamReader re = File.OpenText(Server.MapPath("counter.txt"));

string input = null;

string mycounter = "";

while ((input = re.ReadLine()) != null)


{

mycounter = mycounter + input;

re.Close();

int myInt = int.Parse(mycounter);

myInt = myInt + 1;

TextWriter tw = new StreamWriter(Server.MapPath("counter.txt"));

tw.WriteLine(Convert.ToString(myInt));

tw.Close();

re = File.OpenText(Server.MapPath("counter.txt"));
input = null;
mycounter = "";

while ((input = re.ReadLine()) != null)

mycounter = mycounter + input;

}
re.Close();

return mycounter;

< /script >

'copy this code to the bottom of your .aspx page.

< % Response.Write(counter() + " visited");% >

A brief description of what is going on in this code goes as follows:

a. create a method called counter

b. Call the StreamReader class from the system.IO library and read your
text file

c. Store the value of the text file in a variable


d. Close the StreamReader

e. Open the StreamWriter

f. Add 1 to the variable holding the value from the text file

g. Write the new incremented by 1 value to the text file

h. Close the StreamWriter

This last line

is the line that calls the method when someone visits your homepage for instance.
You can put all of the code at the bottom of the page, or if you are a little more
experienced with c# you could place it in a "code-behind" file or an "include" of class
methods to keep the code a bit more clean.

E) Link for Remoting Example


http://www.c-
sharpcorner.com/UploadFile/ahmadfaraz/RemotingInCsharp11242005053521AM/Remot
ingInCsharp.aspx?ArticleID=e19fc1df-cb91-4710-88a6-1279f20b085a

This link has a good example for Remoting

F) Code for convert file into Zip


using ICSharpCode.SharpZipLib.Zip;

public string createZipFile(string filespath, string nmzipfile)


{
//nmzipfile is the name of the ZipFile to be created.
//filespath is the path where all the files located.
long i = 0;
string FileNames = "";
string Zipfilename = getfilename(nmzipfile);
DirectoryInfo di = new DirectoryInfo(filespath);
ZipOutputStream zipOut = null;

SqlTransaction contrans =null;


try
{
openKeyFactsConnection();
contrans = conlocal.BeginTransaction();

zipOut = new ZipOutputStream(File.Create(nmzipfile));

foreach (FileInfo fi in di.GetFiles())


{
long siz = fi.Length /1024;
i += siz;

Application.DoEvents();

String xname = fi.Name;


string []sptemp=xname.Split('.');

float data=zipOut.Length/(1024*1024);

if ( data<25.0)
{
if (xname != Zipfilename)
{

if (chkdownload(fi.FullName))
{

//---------------
string strinsert = "Insert into
dictationinfo(job_no,created_dt)values('" +
sptemp[0] + "','" +
File.GetCreationTime(fi.FullName) + "')";

comlocal = new
SqlCommand(strinsert, conlocal, contrans);
if (conlocal.State ==
ConnectionState.Closed)
conlocal.Open();
int res1 =
comlocal.ExecuteNonQuery();

//---------------

FileNames += xname + "$";


ZipEntry entry = new
ZipEntry(fi.Name);

FileStream sReader =
File.Open(fi.FullName, FileMode.Open);
byte[] buff = new
byte[Convert.ToInt32(sReader.Length)];
sReader.Read(buff, 0,
(int)sReader.Length);

entry.DateTime = fi.LastWriteTime;

entry.Size = sReader.Length;
sReader.Close();

zipOut.PutNextEntry(entry);

zipOut.Write(buff, 0, buff.Length);
}
}
}

else
{
break;
}
}
zipOut.Finish();

zipOut.Close();

contrans.Commit();

}
catch (Exception ex)
{
errorstring(ex.Message.ToString() + " " +
ex.StackTrace.ToString());
if (zipOut != null)
{
zipOut.Finish();

zipOut.Close();
}
contrans.Rollback();
}
return FileNames;

G) Code for getting the MAC Address of a System


public string getMac()
{
try
{

string[] Ipaddr = new string[3];


System.Net.IPHostEntry Tempaddr = null;
Tempaddr =
(System.Net.IPHostEntry)Dns.GetHostByName(System.Environment.MachineNam
e);
System.Net.IPAddress[] TempAd = Tempaddr.AddressList;

foreach (IPAddress TempA in TempAd)


{
Ipaddr[1] = TempA.ToString();

byte[] ab = new byte[6];


int len = ab.Length;

int r = SendARP((int)TempA.Address, 0, ab, ref len);


string mac = BitConverter.ToString(ab, 0, 6);

Ipaddr[2] = mac;
}
return Ipaddr[2];
}
catch (Exception ex)
{
return "Error";
}
}

H) Code to Encode Password


using System.Security.Cryptography;

public bool EncodePassword(string customerId, string logOnName, string


password)
{
bool result=false;
try
{
customerId.Trim();
logOnName.Trim();
password.Trim();
ASCIIEncoding asciiEncoding = new ASCIIEncoding();
using (MemoryStream memoryStream = new MemoryStream())
{
using (MD5 md5 = MD5CryptoServiceProvider.Create())
{
using (CryptoStream cryptoStream = new
CryptoStream( memoryStream, md5, CryptoStreamMode.Write))
{
byte[] buffer =
asciiEncoding.GetBytes(customerId);
cryptoStream.Write(buffer, 0,
buffer.Length);
buffer = asciiEncoding.GetBytes(logOnName);
cryptoStream.Write(buffer, 0,
buffer.Length);
buffer = asciiEncoding.GetBytes(password);
cryptoStream.Write(buffer, 0,
buffer.Length);
cryptoStream.FlushFinalBlock();
byte[] hash = md5.Hash;

string strpwd = "select e_password from


mpuser(nolock) where login='" + logOnName + "'";
string dbpwd =
Convert.ToString(executscal(strpwd));
string enc=asciiEncoding.GetString(hash);
if (enc == dbpwd)
{
result = true;
passwordEncy = enc;
}
}
}
}

}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString() + " " +
ex.StackTrace.ToString());
throw;
}
return result;
}

I)Link to Send Mail


http://www.codeproject.com/KB/IP/despop3client.aspx

j) Link for the working of OpenFileDialog


http://www.geekpedia.com/tutorial67_Using-OpenFileDialog-to-open-files.html

K) Link for the library(assembly) of Zip file


http://sourceforge.net/project/downloading.php?groupname=sharpdevelop&filename=Sh
arpZipLib_0855_Bin.zip&use_mirror=nchc
L) Link where code to Receiving the mail is….in VB.Net
http://microsoft.apress.com/asptodayarchive/72180/receiving-pop-3-emails-from-an-
aspnet-page

M) Regular Expression to Validate E-mail


1) .+\@.+\..+

2) ^[a-z0-9_\+-]+(\.[a-z0-9_\+-]+)*@[a-z0-9-]+(\.[a-z0-9-]
+)*\.([a-z]{2,4})$

3) ^[a-z0-9,!#\$%&'\*\+/=\?\^_`\{\|}~-]+(\.[a-z0-
9,!#\$%&'\*\+/=\?\^_`\{\|}~-]+)*@[a-z0-9-]+(\.[a-z0-9-]
+)*\.([a-z]{2,})$

N) Link to Encrypt and Decrypt the data in C#.net


http://www.codeproject.com/KB/cs/Cryptography.aspx

O) Link to Serialization notes in ASP.Net


http://www.devarticles.com/c/a/ASP.NET/XML-Serialization-in-ASP.NET/

P) Script to do some work on some particular time or


date

<SCRIPT LANGUAGE="JAVASCRIPT">

today = new Date();

BigDay = new Date("january 22, 2008")


msPerDay = 24 * 60 * 60 * 1000 ;
timeLeft = (BigDay.getTime() - today.getTime());
e_daysLeft = timeLeft / msPerDay;
daysLeft = Math.floor(e_daysLeft);
e_hrsLeft = (e_daysLeft - daysLeft)*24;
hrsLeft = Math.floor(e_hrsLeft);
minsLeft = Math.floor((e_hrsLeft - hrsLeft)*60);
document.write("<br><br><br><br><br><br><br><br><br><br><center><a
href=mailto:abcd@abcd.abcd><img src=go.jpg border=0></a><BR>");
document.write("<font size=1 face=arial><b>" + daysLeft + " days " +
hrsLeft +" hours and " + minsLeft + " minutes till 0!</b>");

</SCRIPT>

Q)Link for Crystal Reports using XML Data Binding


http://dotnetslackers.com/articles/xml/ReportingXMLDataUsingCrystalReportsA
ndWindowsForms.aspx

Potrebbero piacerti anche