Keep in touch

you can keep in touch with my all blogs and sites by install this Toolbar...
http://rworldtoolbar.ourtoolbar.com/

Saturday, March 6, 2010

Get IP Address of Visitor's Machine

Dim ipaddress As String
ipaddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If ipaddress = "" Or ipaddress Is Nothing Then
ipaddress = Request.ServerVariables("REMOTE_ADDR")
End If

When users use any proxies or routers the REMOTE_ADDR returns the IP Address of router or proxy and not the client user’s machine. So first we need to check HTTP_X_FORWARDED_FOR.

Confirm Before Page Close

Try using the confirm method on the onUnLoad event:

if (confirm("Are you sure you want to leave) == true)
{ return true; }
else
{ return false; }

Export A File and Delete it from Server

Private Sub DownloadFile()
Response.ContentType = ContentType
Response.AppendHeader("Content-Disposition", _
"attachment; filename=myFile.txt")
Response.WriteFile(Server.MapPath("~/uploads/myFile.txt"))
Response.Flush()
System.IO.File.Delete(Server.MapPath("~/uploads/myFile.txt"))
Response.End()
End Sub

URL Rewritting: Hide Web Page Extentsion

write this code in ur Global.asax

Private Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
Dim fullOrigionalpath As String = Request.Url.ToString()
If Not fullOrigionalpath.EndsWith(".aspx") Then
Context.RewritePath(fullOrigionalpath.Substring(fullOrigionalpath.IndexOf("/", 9)) & ".aspx")
End If
End Sub

Check if Url Exists or not in ASP.NET

Public Shared Function IsValidUrl(ByVal Url As String) As Boolean
Dim sStream As Stream
Dim URLReq As HttpWebRequest
Dim URLRes As HttpWebResponse
Try
URLReq = WebRequest.Create(Url)
URLRes = URLReq.GetResponse()
sStream = URLRes.GetResponseStream()
Dim reader As String = New StreamReader(sStream).ReadToEnd()
Return True
Catch ex As Exception
‘Url not valid
Return False
End Try
End Function

Convert A Number To Month Name and Month Name to Number in ASP.NET

For Converting A Number To Month Name Use:

dim MyMonthNumber as integer = 7
MonthName(MyMonthNumber)

or

Format(New Date(2009, MyMonthNumber, 1), "MMMMM")

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

For Converting A Number To Month Name Use:

dim MyMonthName as String = "July"
CDate("01-" & MyMonthName & "-2009").Month

Get Country Name by Client IP

Add WebService Reference of

http://www.webservicex.net/geoipservice.asmx?wsdl

Here is the code:

Dim objWebServiceX As New webservicex.GeoIPService
Dim countryName As String = objWebServiceX.GetGeoIP(Request.ServerVariables("REMOTE_ADDR")).CountryName
Response.Write(countryName & "
")