Friday, December 3, 2010

Auto Page Rediret in asp.net

//meta http-equiv="refresh" content="5; url=http://www.mitthu.in/sms2send.aspx"\\

use //="<" \\=">"

Thursday, September 9, 2010

Number to Text in VB6 Indian Style

Dim valforunit(9) As String
Dim valforhun(9) As String
Dim valforten(9) As String
Dim allval As String
Public Function Text_to_Word(PNum As Double) As String
valforunit(1) = "One"
valforunit(2) = "Two"
valforunit(3) = "Three"
valforunit(4) = "Four"
valforunit(5) = "Five"
valforunit(6) = "Six"
valforunit(7) = "Seven"
valforunit(8) = "Eight"
valforunit(9) = "Nine"

valforten(1) = "Eleven"
valforten(2) = "Twelve"
valforten(3) = "Thirteen"
valforten(4) = "Fourteen"
valforten(5) = "Fiveteen"
valforten(6) = "Sixteen"
valforten(7) = "Seventeen"
valforten(8) = "Eighteen"
valforten(9) = "Nineteen"
valforten(0) = "Ten"

valforhun(1) = "Ten"
valforhun(2) = "Twenty"
valforhun(3) = "Thirty"
valforhun(4) = "Forty"
valforhun(5) = "Fifty"
valforhun(6) = "Sixty"
valforhun(7) = "Seventy"
valforhun(8) = "Eighty"
valforhun(9) = "Ninety"
allval = ""
Dim sanstr As Variant
X = PNum
i = 2
If Len(X) > 2 Then
a = Len(X) / 2
a = CStr(a)
b = InStr(1, a, ".", 1)
If b <> -1 And b <> 0 Then a = Mid(a, 1, b)
a = CInt(a) + 1
Else
a = 1
End If
For k = 1 To a
If k = 1 Then
sanstr = Right(X, 2)
ElseIf k = 2 Then
sanstr = Left(Right(X, 3), 1)
Else
sanstr = Right(X, k + i)
m = Len(sanstr) Mod 2
If m = 1 Then
sanstr = Left(sanstr, 2)
Else
sanstr = Left(sanstr, 1)
End If
i = i + 1
End If
Call sanfun(sanstr)
If k = 2 And sanstr <> "" Then
sanstr = sanstr & " Hundred "
ElseIf k = 3 And sanstr <> "" And sanstr <> " " Then
sanstr = sanstr & " Thousand "
ElseIf k = 4 And sanstr <> "" Then
If sanstr = "One" Then
sanstr = sanstr & " Lakh "
Else
sanstr = sanstr & " Lakhs "
End If
ElseIf k = 5 And sanstr <> "" Then
If sanstr = "One" Then
sanstr = sanstr & " Crore "
Else
sanstr = sanstr & " Crores "
End If
End If
allval = sanstr & allval

Next
If Trim(Right(allval, 5)) = "And" Then
allval = Trim(Replace(Trim(allval), "And", ""))
End If
Text_to_Word = allval
End Function
Private Sub sanfun(ByRef X As Variant)
Dim arr() As String
ReDim arr(Len(X))
For j = 0 To Len(X) - 1
a = Right(X, j + 1)
a = Left(a, 1)
arr(j) = a
Next
asize = UBound(arr)
If asize = 1 Then
X = valforunit(arr(0))
ElseIf asize = 2 Then
If paise = 1 Then
X = valforunit(arr(1)) & " " & valforunit(arr(0))
Exit Sub
End If
If arr(1) = 1 Then
X = valforten(arr(0))
Else
X = valforhun(arr(1)) & " " & valforunit(arr(0))
End If
End If
End Sub

Private Sub Command1_Click()
MsgBox Text_to_Word(Text1.Text)
End Sub

Friday, May 28, 2010

Making Uninstaller for vb.net Application

VS2005 Code
-----------
Deployment VB.NET project (with uninstall file)
In Visual Studio.NET:
Ø File > Add Project > New Project > Setup & Deployment Project > Setup Project
(Enter name and location)
Ø Add (right-click in Application Folder > Add > Project Output):
· Primary Output
Ø If an error occurs about files that should be excluded > In Solution Explorer select your Setup project > Exclude those files (right-click > exclude)

Ø Build > Build ’name project’

In Windows:
-----------
Ø Create an Uninstall.bat file containing:
C:\WINDOWS\system32\MsiExec.exe /I{productcode}

(Path depends of your Windows version, check where your system32 folder is located)
(You’ll find the productcode in Visual Studio.NET > Tab Properties in the setup project you’ve just created)

Ø Open the setup project in Visual Studio.NET if you closed it
Ø Add (right-click in Application Folder):
· Add > Project Output > File > Uninstall.bat
· Create New Shortcut > Application Folder > Primary Output (enter a name)
· Create New Shortcut > Application Folder > Uninstall.bat (enter a name)
· Add > File > add .ico files you want to use for the shortcuts
Ø Shortcuts properties > ‘icon’ property (use the icons you’ve just added)
Ø Move the shortcuts to User’s Desktop/User’s Programs Menu (you can also create subfolders)
Ø Build > Rebuild ’name project’

Tuesday, May 25, 2010

Display Custome Message on Crystal Report Textbox

Dim objRpt As New rptAppoinment
Dim myMsg As CrystalDecisions.CrystalReports.Engine.TextObject

myMsg = CType(objRpt.ReportDefinition.ReportObjects.Item("Text8"), CrystalDecisions.CrystalReports.Engine.TextObject)

myMsg.Text = "This is my custom message in Crystal Report."

Fill ListView with SQL Server Database Record

CN.ConnectionString = "Data Source = " & System.Environment.MachineName & "\SQLEXPRESS; Initial Catalog = YourDB;Integrated Security = True"

CN.Open()

Dim strSQL As String
Ds.Clear()

strSQL = "SELECT Field1, Field2 FROM TableName"
Da = New SqlDataAdapter(strSQL, CN)
Da.Fill(Ds, "TableName")
CN.Close()
MaxRows = Ds.Tables("TableName").Rows.Count
inc = -1

If MaxRows = 0 Then
MsgBox("No record found for your search!", MsgBoxStyle.Information)
Ds.Clear()
ListView1.Clear()
Exit Sub
Else
ListView1.Clear()
ListView1.View = View.Details
Dim dt As DataTable = Ds.Tables("TableName")

For Each c As DataColumn In dt.Columns
ListView1.Columns.Add(c.ColumnName, 100)
Next

For Each r As DataRow In dt.Rows
Dim item As New ListViewItem(r(0).ToString())
For i As Integer = 1 To dt.Columns.Count - 1
item.SubItems.Add(r(i))
Next
ListView1.Items.Add(item)
Next
End If

If CN.State = ConnectionState.Open Then CN.Close()

Wednesday, May 19, 2010

Declare Global Variables in VB.NET and C#

C#
-----
namespace Module{
public class Module1
{
public static int moduleinteger;
}
}

access like Module1.moduleinteger


VB.net
------
Module Module1
Public moduleinteger As Integer
End Module

Tuesday, April 27, 2010

Context Menu Live Example

Context Menu in vb.net
----------------------
Public Class Form1
Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
If e.Button = MouseButtons.Right Then
ContextMenuStrip1.Show(Me, New Point(e.X, e.Y))
End If
End Sub

Private Sub MoveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MoveToolStripMenuItem.Click
MsgBox("Item Moved")
End Sub
End Class

Display Javascript Alert in ASP.NET

Alert.aspx
----------

Public Sub MyMsgBox(ByVal Message As String)
System.Web.HttpContext.Current.Response.Write("[SCRIPT LANGUAGE=""JavaScript""]" & vbCrLf)
' System.Web.HttpContext.Current.Response.Write("alert(""Hello Sir"")" & vbCrLf)
System.Web.HttpContext.Current.Response.Write("alert(""" & message & """)" & vbCrLf)
System.Web.HttpContext.Current.Response.Write("[/" & "SCRIPT" & "]")
End Sub
---------------------------------------------------------------------------------
Private Sub Button1_click(ByVal o As Object, ByVal e As EventArgs)
MyMsgBox("hello")
End Sub
---------------------------------------------------------------------------------
[asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_click"/]

Monday, April 19, 2010

KyeDown N KeyPress Event in VB.NET

KyeDown N KeyPress Event in VB.NET
-----------------------------------

Private Sub TextBox1_Keydown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown, TextBox2.KeyDown
If e.KeyCode = Keys.Tab Then
If sender.Name = "TextBox1" Then
TextBox2.Focus()
e.Handled = True
ElseIf sender.Name = "TextBox2" Then
TextBox1.Focus()
e.Handled = True
End If
End If
End Sub

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress, TextBox2.KeyPress
If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then
If sender.name = "TextBox1" Then
TextBox2.Focus()
e.Handled = True
ElseIf sender.name = "TextBox2" Then
TextBox1.Focus()
e.Handled = True
End If
End If
End Sub

Send Email in asp.net using Gmail SMTP with file attachment

web.config
-----------
[configuration]
[system.net]
[mailSettings]
[smtp from="xxxx@gmail.com"]
[network host="smtp.gmail.com" port="587" userName="xxxx@gmail.com" password="xxxx" defaultCredentials="false" /]
[/smtp]
[/mailSettings]
[/system.net]
[/configuration]


Default.aspx
------------

Private Sub SendMail(ByVal source As Object, ByVal e As EventArgs)
Dim FileName As String = Server.MapPath("./files/twitter_logo.png")
Dim smtp As New System.Net.Mail.SmtpClient()
Dim smail As New System.Net.Mail.MailMessage
smail.To.Add(New System.Net.Mail.MailAddress("xxxx@gmail.com"))
smail.From = New System.Net.Mail.MailAddress("xxxx@gmail.com", "Support System")
smail.Subject = "Alert by Support System"
smail.IsBodyHtml = "true"
smail.Body = "This is test mail by xxxx"
smtp.EnableSsl = True
smail.Attachments.Add(New System.Net.Mail.Attachment(FileName))
smtp.Send(smail)
Response.Write("Email Sent Successfully!")
End Sub

Additional Helpful Code
-----------------------

This is the C# code to send emails in HTML format
--------------------------------------------------
MailAddress SendFrom = new MailAddress(txtFrom.Text);
MailAddress SendTo = new MailAddress(txtTo.Text);
MailMessage MyMessage = new MailMessage(SendFrom, SendTo);

MyMessage.Subject = "Subject here";
MyMessage.IsBodyHtml = true;
MyMessage.Priority = MailPriority.Normal;
MyMessage.Body = "Some Html Body here";
SmtpClient emailClient = new SmtpClient();
emailClient.UseDefaultCredentials = true;
emailClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
emailClient.Host = "localhost";
emailClient.Send(MyMessage);

-------------------------------------------------------------------------

System.Web.Mail.MailMessage objMail = new System.Web.Mail.MailMessage();
objMail.BodyFormat = System.Web.Mail.MailFormat.Html;
objMail.From = "admin@fodra.org.in";
objMail.To = "";
objMail.Subject = "test";
objMail.Priority = System.Web.Mail.MailPriority.High;
string l_body;

l_body="Test";

objMail.Body = l_body;
System.Web.Mail.SmtpMail.Send(objMail);

Sunday, April 18, 2010

How to check EOF with SqlDataReader?

VB.NET
-------
Dim myconnection As SqlConnection
Dim mycmd As SqlCommand
Dim strSql As String
Dim myReader As SqlDataReader

myconnection = New SqlConnection("Server=localhost;uid=sa;password=;database=northwind;")
strSql = "Select count(*) from employees;Select * from employees"
mycmd = New SqlCommand(strSql, myconnection)
myconnection.Open()

Dim count As Integer = CInt(mycmd.ExecuteScalar())
myReader = mycmd.ExecuteReader(CommandBehavior.CloseConnection)
If count = 0 Then
Response.Write("No records found")
Else
myReader.NextResult()
While myReader.Read()
Response.Write(myReader("Employeeid").ToString() + "
")
End While
End If

-------------------------------------------------------------------------------

C#
----

SqlConnection myconnection ;
SqlCommand mycmd ;
string strSql ;
SqlDataReader myReader ;
myconnection = new SqlConnection("Server=localhost;uid=sa;password=;database=northwind;");
strSql = "Select count(*) from employees;Select * from employees";
mycmd = new SqlCommand(strSql, myconnection);
myconnection.Open();
int count=(int) mycmd.ExecuteScalar() ;
myReader = mycmd.ExecuteReader(CommandBehavior.CloseConnection);
if (count==0 )
{
Response.Write("No records found");
}
else
{
myReader.NextResult ();
while(myReader.Read ())
{
Response.Write(myReader["Employeeid"].ToString () + "
");
}
}