mac id -Media Access Control ID
you have to add reference of
Imports Microsoft.Win32
Imports System.Management
Imports System.IO
VB::
Dim mc As ManagementClass = New ManagementClass("Win32_NetworkAdapterConfiguration")
Dim moc As ManagementObjectCollection = mc.GetInstances()
For Each mo As ManagementObject In moc
If (MACAddress = String.Empty) Then ' only return MAC Address from first card
If Convert.ToBoolean(mo("IPEnabled")) = True Then
MACAddress = mo("MacAddress").ToString()
mo.Dispose()
End If
End If
Next
MessageBox.Show(MACAddress)
C#:
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
string MACAddress = String.Empty;
foreach (ManagementObject mo in moc)
{
if (MACAddress == String.Empty) // only return MAC Address from first card
{
if ((bool)mo["IPEnabled"] == true) MACAddress = mo["MacAddress"].ToString();
}
mo.Dispose();
}
MACAddress = MACAddress.Replace(":", "");
MessageBox.Show(MACAddress);
Sunday, October 18, 2009
Sunday, October 4, 2009
Difference between two dates in C#
public int GetTotalDays(DateTime startedDateTime)
{
//get the current date
DateTime nowDate = System.DateTime.Now;
//use timespan to get the number of days
System.TimeSpan span = nowDate - startedDateTime;
int days = (int)span.TotalDays;
return days;
}
{
//get the current date
DateTime nowDate = System.DateTime.Now;
//use timespan to get the number of days
System.TimeSpan span = nowDate - startedDateTime;
int days = (int)span.TotalDays;
return days;
}
Saturday, October 3, 2009
want to revere a string ??? solution is here c# ,VB
we can reverse a string in so many methods..
method 1
string str="Suresh Varma";
char[] rev=str.ToChatArray(str);
Array.Reverse(rev);
Response.Write(new string(rev));
out put...> amraV hseruS
method 2:
string str="9000588819";
string rev="";
for ( int i=0;i < str.length;i++)
{
rev+=str.SubString(str.length-i,1);
}
response.write(rev);
o/p 9188850009
method 3:(works only in VB.net)
Import Microsoft.VisualBasic
dim str as new string=strReverse("varma")
response.Write(str)
o/p amrav
method 1
string str="Suresh Varma";
char[] rev=str.ToChatArray(str);
Array.Reverse(rev);
Response.Write(new string(rev));
out put...> amraV hseruS
method 2:
string str="9000588819";
string rev="";
for ( int i=0;i < str.length;i++)
{
rev+=str.SubString(str.length-i,1);
}
response.write(rev);
o/p 9188850009
method 3:(works only in VB.net)
Import Microsoft.VisualBasic
dim str as new string=strReverse("varma")
response.Write(str)
o/p amrav
Friday, June 19, 2009
How to make ASP.Net FileUpload control readonly
We can make the ASP.Net FileUpload control readonly by setting the ContentEditable property to false.
in .aspx file write.... fileupload id="fileUpload1" runat="server" contenteditable="false"
note : intellisence won't shows ContentEditable property.
The other way of achieving it by restricting users to type in any characters i.e. return false on key press, key up and on paste event to prevent users pasting any values directly.
Refer the below code snippet that helps in doing that,
fileUploadSri.Attributes.Add("onkeypress", "return false;");
fileUploadSri.Attributes.Add("onkeyup", "return false;");
fileUploadSri.Attributes.Add("onpaste", "return false;");
in .aspx file write.... fileupload id="fileUpload1" runat="server" contenteditable="false"
note : intellisence won't shows ContentEditable property.
The other way of achieving it by restricting users to type in any characters i.e. return false on key press, key up and on paste event to prevent users pasting any values directly.
Refer the below code snippet that helps in doing that,
fileUploadSri.Attributes.Add("onkeypress", "return false;");
fileUploadSri.Attributes.Add("onkeyup", "return false;");
fileUploadSri.Attributes.Add("onpaste", "return false;");
Sunday, May 31, 2009
how to send E-Mail from your asp.net web site
use namespace System.Net.Mail;
use this code in send button click oe where ever u want
try
{
SmtpClient sc = new SmtpClient("smtp.gmail.com", 25);
sc.EnableSsl = true;
sc.Credentials = new System.Net.NetworkCredential(TextFrom.Text, textPwd.Text);
sc.Send(TextFrom.Text, TextTo.Text, TextSubject.Text, TextMatter.Text);
Label1.Text = "Your Message sent Successfully";
}
catch
{
Label1.Text = "An Error has occured;Plz Enter Valid data";
}
use this code in send button click oe where ever u want
try
{
SmtpClient sc = new SmtpClient("smtp.gmail.com", 25);
sc.EnableSsl = true;
sc.Credentials = new System.Net.NetworkCredential(TextFrom.Text, textPwd.Text);
sc.Send(TextFrom.Text, TextTo.Text, TextSubject.Text, TextMatter.Text);
Label1.Text = "Your Message sent Successfully";
}
catch
{
Label1.Text = "An Error has occured;Plz Enter Valid data";
}
Saturday, May 30, 2009
Can we use two different Languages in one website development?
Yes,But we have to follow some rules.
add /App_Code folder to your solution .
make two sub-folders
like:
App_Code
/VB (Your sub folder name)
myClass1.vb (Your class coded in VB)
/CS (Your sub folder name)
myClass2.cs (Your Class coded in C#)
after that go to web.config file
< compilation > <codesubdirectories>compilation
< codeSubDirectories >
< add directoryName="VB" > < "/add" >
< add directoryName="CS"">""<"/add" >
< codeSubDirectories" >
< /compilation >
< codesubdirectories >
< add directoryname="VB" > < /add >
< add directoryname="CS" > </add >
< codesubdirectories >
< /codesubdirectories > < codesubdirectories >
< add directoryname="CS" > </add >
< codesubdirectories >
< /codesubdirectories > < compilation < > codesubdirectories > < add directoryname="VB" > < /add > < add directoryname="CS" > < /add > < codesubdirectories > </codesubdirectories >
< /codesubdirectories >
</compilation >
//Note:You are not required to name them "VB" and "CS"{Sub-folder names} as we did ,You can use whatever name tickles your fancy.
add /App_Code folder to your solution .
make two sub-folders
like:
App_Code
/VB (Your sub folder name)
myClass1.vb (Your class coded in VB)
/CS (Your sub folder name)
myClass2.cs (Your Class coded in C#)
after that go to web.config file
< compilation > <codesubdirectories>compilation
< codeSubDirectories >
< add directoryName="VB" > < "/add" >
< add directoryName="CS"">""<"/add" >
< codeSubDirectories" >
< /compilation >
< codesubdirectories >
< add directoryname="VB" > < /add >
< add directoryname="CS" > </add >
< codesubdirectories >
< /codesubdirectories > < codesubdirectories >
< add directoryname="CS" > </add >
< codesubdirectories >
< /codesubdirectories > < compilation < > codesubdirectories > < add directoryname="VB" > < /add > < add directoryname="CS" > < /add > < codesubdirectories > </codesubdirectories >
< /codesubdirectories >
</compilation >
//Note:You are not required to name them "VB" and "CS"{Sub-folder names} as we did ,You can use whatever name tickles your fancy.
Friday, May 1, 2009
How to set maximum length to Multiline TextBox in ASP.NET 2.0
First of all this is a bug in .net..We cant set MaxLength while property of TextBox is set to Multiline.
We can achieve this by using regular expression validator.
<asp:RegularExpressionValidator ID="MaxLengthValidator" ControlToValidate="AddersTxtbox" Text="Max length is 20" ValidationExpression="^[\s\S]{0,20}$" runat="server" />
We can achieve this by using regular expression validator.
<asp:RegularExpressionValidator ID="MaxLengthValidator" ControlToValidate="AddersTxtbox" Text="Max length is 20" ValidationExpression="^[\s\S]{0,20}$" runat="server" />
Subscribe to:
Comments (Atom)
