Santosh 的个人资料Santosh Kumar照片日志列表更多 工具 帮助

日志


ASP.Net, Gridview paging simplified

 
Imports System
Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Configuration
Imports MySql.Data.MySqlClient
 
Public Shared Sub BindGridView(ByRef faGV As GridView, ByVal faQry As String, Optional ByVal faIndex As Integer = 0)
    Dim dsPage As New DataSet
    If faIndex >= 0 Then faGV.PageIndex = faIndex
    BindDataSet(dsPage, faQry)
    faGV.DataSource = dsPage
    faGV.DataBind()
End Sub
 
Public Shared Sub BindDataSet(ByRef faDS As DataSet, ByVal faQry As String)
    Dim vMySqlConnection As MySqlConnection = Nothing
    Dim vMySqlDataAdapter As MySqlDataAdapter = Nothing
    Dim vMySqlCommand As MySqlCommand = Nothing
    Try
        vMySqlConnection = New MySqlConnection(ConfigurationManager.AppSettings("WebConfigMySql"))
        vMySqlCommand = vMySqlConnection.CreateCommand
        vMySqlCommand.CommandText = faQry
        vMySqlCommand.CommandType = CommandType.Text
        vMySqlConnection.Open()
        vMySqlDataAdapter = New MySqlDataAdapter(vMySqlCommand)
        faDS = New DataSet
        vMySqlDataAdapter.Fill(faDS)
 
    Catch ex As Exception
        faDS = Nothing
 
    Finally
        If Not vMySqlDataAdapter Is Nothing Then vMySqlDataAdapter.Dispose()
        If Not vMySqlCommand Is Nothing Then vMySqlCommand.Dispose()
        If Not vMySqlConnection Is Nothing Then vMySqlConnection.Dispose()
    End Try
End Sub
 
»»»»»»»   by Santosh Kumar ? Original @ http://santu4you.spaces.live.com
  

VB.Net, ASP.Net, Working with Cryptography

 
Imports System.IO
Imports Microsoft.VisualBasic
Imports System.Security.Cryptography
 
Public Class clsCrypto
 
    Private Shared Function GetCryptoKey() As String
        Dim vRet As String
        vRet = "jstbhgope"
        Return vRet
    End Function
 
 
    Private Shared Function GetCryptoBytes() As Byte()
        Dim vBytes() As Byte = {&H90, &H34, &H56, &H78, &H12, &HAB, &HCD, &HEF}
        Return vBytes
    End Function
 
 
    Public Shared Function DoEnCrypt(ByVal vStr As String) As String
 
        Dim vRgbKEY() As Byte = {}
        Dim vRgbIV() As Byte = GetCryptoBytes()
 
        Try
            vRgbKEY = System.Text.Encoding.UTF8.GetBytes(Left(GetCryptoKey(), 8))
 
            Dim des As New DESCryptoServiceProvider
            Dim inputByteArray() As Byte = Encoding.UTF8.GetBytes(vStr)
            Dim ms As New MemoryStream
            Dim cs As New CryptoStream(ms, des.CreateEncryptor(vRgbKEY, vRgbIV), CryptoStreamMode.Write)
            cs.Write(inputByteArray, 0, inputByteArray.Length)
            cs.FlushFinalBlock()
            Return Convert.ToBase64String(ms.ToArray())
 
        Catch ex As Exception
            Return ex.Message
 
        End Try
 
    End Function
 
 
    Public Shared Function DoDeCrypt(ByVal vStr As String) As String
        Dim vRgbKEY() As Byte = {}
        Dim vRgbIV() As Byte = GetCryptoBytes()
        Dim inputByteArray(vStr.Length) As Byte
 
        Try
            vRgbKEY = System.Text.Encoding.UTF8.GetBytes(Left(GetCryptoKey(), 8))
            Dim des As New DESCryptoServiceProvider
            inputByteArray = Convert.FromBase64String(vStr)
            Dim ms As New MemoryStream
            Dim cs As New CryptoStream(ms, des.CreateDecryptor(vRgbKEY, vRgbIV), CryptoStreamMode.Write)
 
            cs.Write(inputByteArray, 0, inputByteArray.Length)
            cs.FlushFinalBlock()
            Dim encoding As System.Text.Encoding = System.Text.Encoding.UTF8
 
            Return encoding.GetString(ms.ToArray())
 
        Catch ex As Exception
            Return ex.Message
 
        End Try
 
    End Function
 
End Class
  
»»»»»»»   by Santosh Kumar ? Original @ http://santu4you.spaces.live.com
 

Oracle, How to select records from record no N1 to N2

 
SQL> SELECT ROWNUM, E.* FROM EMP E /*This is the table*/;
 
    ROWNUM      EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
---------- ---------- ---------- --------- ---------- --------- ---------- ---------- ----------
         1       7369 SMITH      CLERK           7902 17-DEC-80       -800                    20
         2       7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
         3       7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
         4       7566 JONES      MANAGER         7839 02-APR-81       2975                    20
         5       7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
         6       7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
         7       7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
         8       7788 SCOTT      ANALYST         7566 09-DEC-82       3000     5000.5         20
         9       7839 KING       PRESIDENT            17-NOV-81       5000                    10
        10       7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
        11       7876 ADAMS      CLERK           7788 12-JAN-83       1100                    20
        12       7900 JAMES      CLERK           7698 03-DEC-81        950                    30
        13       7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
        14       7934 MILLER     CLERK           7782 23-JAN-82       1300                    10
 
14 rows selected.
 
SQL> SELECT * FROM( /*This will select 5th to 10th records*
  2  SELECT ROWNUM RN, E.* FROM EMP E WHERE ROWNUM  <= 10
  3  ) WHERE RN  >= 5
  4  /
 
        RN      EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
---------- ---------- ---------- --------- ---------- --------- ---------- ---------- ----------
         5       7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
         6       7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
         7       7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
         8       7788 SCOTT      ANALYST         7566 09-DEC-82       3000     5000.5         20
         9       7839 KING       PRESIDENT            17-NOV-81       5000                    10
        10       7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
 
6 rows selected.
  
»»»»»»»   by Santosh Kumar ? Original @ http://santu4you.spaces.live.com
 

Oracle, How to select last N records

 
SQL> SELECT ROWNUM, E.* FROM EMP E /*This is the table*/;
 
    ROWNUM      EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
---------- ---------- ---------- --------- ---------- --------- ---------- ---------- ----------
         1       7369 SMITH      CLERK           7902 17-DEC-80       -800                    20
         2       7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
         3       7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
         4       7566 JONES      MANAGER         7839 02-APR-81       2975                    20
         5       7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
         6       7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
         7       7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
         8       7788 SCOTT      ANALYST         7566 09-DEC-82       3000     5000.5         20
         9       7839 KING       PRESIDENT            17-NOV-81       5000                    10
        10       7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
        11       7876 ADAMS      CLERK           7788 12-JAN-83       1100                    20
        12       7900 JAMES      CLERK           7698 03-DEC-81        950                    30
        13       7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
        14       7934 MILLER     CLERK           7782 23-JAN-82       1300                    10
 
14 rows selected.
 
SQL> SELECT * FROM( /*This will select last five records*/
  2      SELECT * FROM(
  3          SELECT ROWNUM RN, E.* FROM EMP E
  4      ) ORDER BY RN DESC
  5  ) WHERE ROWNUM  <= 5
  6  /
 
        RN      EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
---------- ---------- ---------- --------- ---------- --------- ---------- ---------- ----------
        14       7934 MILLER     CLERK           7782 23-JAN-82       1300                    10
        13       7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
        12       7900 JAMES      CLERK           7698 03-DEC-81        950                    30
        11       7876 ADAMS      CLERK           7788 12-JAN-83       1100                    20
        10       7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
 
»»»»»»»   by Santosh Kumar ? Original @ http://santu4you.spaces.live.com
 

Oracle, How to select random records

 
SQL> SELECT ROWNUM, E.* FROM EMP E /*This is the table*/;
 
    ROWNUM      EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
---------- ---------- ---------- --------- ---------- --------- ---------- ---------- ----------
         1       7369 SMITH      CLERK           7902 17-DEC-80       -800                    20
         2       7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
         3       7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
         4       7566 JONES      MANAGER         7839 02-APR-81       2975                    20
         5       7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
         6       7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
         7       7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
         8       7788 SCOTT      ANALYST         7566 09-DEC-82       3000     5000.5         20
         9       7839 KING       PRESIDENT            17-NOV-81       5000                    10
        10       7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
        11       7876 ADAMS      CLERK           7788 12-JAN-83       1100                    20
        12       7900 JAMES      CLERK           7698 03-DEC-81        950                    30
        13       7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
        14       7934 MILLER     CLERK           7782 23-JAN-82       1300                    10
 
14 rows selected.
 
SQL> SELECT ROWNUM, E.* FROM EMP E ORDER BY DBMS_RANDOM.VALUE /*This will randimise the rows*/;
 
    ROWNUM      EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
---------- ---------- ---------- --------- ---------- --------- ---------- ---------- ----------
         3       7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
        12       7900 JAMES      CLERK           7698 03-DEC-81        950                    30
         4       7566 JONES      MANAGER         7839 02-APR-81       2975                    20
         1       7369 SMITH      CLERK           7902 17-DEC-80       -800                    20
         6       7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
        13       7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
         5       7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
        14       7934 MILLER     CLERK           7782 23-JAN-82       1300                    10
         8       7788 SCOTT      ANALYST         7566 09-DEC-82       3000     5000.5         20
         2       7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
        10       7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
        11       7876 ADAMS      CLERK           7788 12-JAN-83       1100                    20
         7       7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
         9       7839 KING       PRESIDENT            17-NOV-81       5000                    10
 
14 rows selected.
 
SQL> SELECT ROWNUM, E.* FROM( /*This will select 5 random records*/
  2  SELECT * FROM EMP ORDER BY DBMS_RANDOM.VALUE
  3  ) E WHERE ROWNUM <= 5
  4  /
 
    ROWNUM      EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
---------- ---------- ---------- --------- ---------- --------- ---------- ---------- ----------
         1       7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
         2       7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
         3       7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
         4       7788 SCOTT      ANALYST         7566 09-DEC-82       3000     5000.5         20
         5       7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
  
»»»»»»»   by Santosh Kumar ? Original @ http://santu4you.spaces.live.com
 

VB.Net, Finding very first day number for Sun, Mon, ..., Sat of the Year

 
Public Shared Function GetVery1stDayNoOfTheYear(ByVal faDay As String, ByVal faYear As Integer) As Integer
    Dim vRet As Integer = 0
    For vRet = 1 To 7
        If UCase(Format(CDate("0" & vRet & "-Jan-" & faYear), "ddd")) = UCase(faDay) Then
            Exit For
        End If
    Next
    Return vRet
End Function 
 
Input: GetVery1stDayNoOfTheYear("SUN",2008), Output: 6
Input: GetVery1stDayNoOfTheYear("SUN",2009), Output: 4
Input: GetVery1stDayNoOfTheYear("MON",2009), Output: 5
 
»»»»»»»   by Santosh Kumar ? Original @ http://santu4you.spaces.live.com
 

ASP.Net, Designing a site visit counter module

 
There are many sites offering visit analysis for your web site including google. Once you register with them, you will get some client side script. You can put them in each of your page, and thing are over. You can try your own visit analysis module with the help of the following codes. It uses an xml file i.e. AppVisitCount.Xml, the structure is given below. All you need is to call the following functions
 
LetVisitCount(): For page load of every aspx file or master file
GetVisitCount(): To know the current visit count
GetCountBoard(): To have the following output
 
 1   5   0   8   1   9   4   7 
 
You can also write additional functions to maintain a database level logs for capturing statistics for various analysis. The function LetVisitCount() is the right place for calling your functions for such data captures.
 
'''''''''file:AppVisitCount.Xml
 
<?xml version="1.0" standalone="yes"?>
<table>
  <row>
    <hitcounter>15081947</hitcounter>
  </row>
</table>
 
'''''''''code:forVisitCount
 
Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Xml
Imports System.IO
 
Private Shared Function GetVisitCount() As Long
    Dim vDs As New DataSet
    Dim vHits As Long = 0
    vDs.ReadXml(HttpContext.Current.Request.PhysicalApplicationPath & "\AppVisitCount.Xml")
    vHits = CLng(vDs.Tables(0).Rows(0).Item("hitcounter").ToString)
    Return vHits
End Function
 
Public Shared Sub LetVisitCount()
    Dim vHits As Long = 0
    If HttpContext.Current.Session("hitcounter") Is Nothing Then
        vHits = SetVisitCount()
        HttpContext.Current.Session("hitcounter") = vHits
    Else
        vHits = GetVisitCount()
    End If
End Sub
 
Public Shared Function GetCountBoard() As String
    Dim vHitsBoard As String = ""
    If Not HttpContext.Current.Session("Hits") Is Nothing Then
        Dim vHits As String = Format(CLng(HttpContext.Current.Session("hitcounter")), "0000000")
        Dim vCnt As Integer = Len(vHits)
        Dim vCtr As Integer = 0
        vHitsBoard = vHitsBoard & "<table border=1 cellpadding=1 cellspacing=0><tr>"
        For vCtr = 1 To vCnt
            vHitsBoard = vHitsBoard & "<td height=25px bgcolor='#000000' "
            vHitsBoard = vHitsBoard & "style='color:#ffffff;font-weight:bold'>"
            vHitsBoard = vHitsBoard & Mid(vHits, vCtr, 1) & "</td>"
        Next
        vHitsBoard = vHitsBoard & "</tr></table>"
    End If
    Return vHitsBoard
End Function
 
Private Shared Function SetVisitCount() As Long
    Dim vDs As New DataSet
    Dim vHits As Long = 0
    vDs.ReadXml(HttpContext.Current.Request.PhysicalApplicationPath & "\AppVisitCount.Xml")
    vHits = CLng(vDs.Tables(0).Rows(0).Item("hitcounter").ToString) + 1
    vDs.Tables(0).Rows(0).Item("hitcounter") = vHits
    vDs.WriteXml(HttpContext.Current.Request.PhysicalApplicationPath & "\AppVisitCount.Xml")
    Return vHits
End Function
 
»»»»»»»   by Santosh Kumar ?
Original @ http://santu4you.spaces.live.com
 

ASP.Net, Downloading files and images which are kept outside the web application folder

 
There are many situations where your application requires giving facilities for uploading files. If this files require sharing publically you should keep it in your web application folder so that search engines can easily search it and index then. This will also help you to ease your site search engines also. But it not a good idea to keep it inside your web application folder if you want to make it secured from unauthorized access. In such case you must keep this folder outside. But this will restrict you to use href tag from downloading. The following code will help you.
 
Imports Microsoft.VisualBasic
Imports System.Data
Imports System.IO
 
Public Shared Function DoDownload_File(ByVal faType As String, ByVal faFile As String, ByVal faPath As String) As Boolean 
    Dim vRet As Boolean = False
    Try
        HttpContext.Current.Response.ContentType = "application/" & faType
        HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=" & faFile)
        HttpContext.Current.Response.TransmitFile(faPath)
        HttpContext.Current.Response.End()
        vRet = True
    Catch ex As Exception
        vRet = False
    Finally
        'doNothing
    End Try
    Return vRet
End Function
 
Public Shared Function DoDownload_Image(ByVal faFile As String, ByVal faPath As String) As Boolean 
    Dim vRet As Boolean = False
    Try
        Dim contenttype As String = "image/" & Path.GetExtension(faFile).Replace(".", "")
        Dim fs As FileStream = New FileStream(faPath & faFile, FileMode.Open, FileAccess.Read)
        Dim br As BinaryReader = New BinaryReader(fs)
        Dim bytes As Byte() = br.ReadBytes(Convert.ToInt32(fs.Length))
        br.Close()
        fs.Close()
        HttpContext.Current.Response.Buffer = True
        HttpContext.Current.Response.Charset = ""
        HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache)
        HttpContext.Current.Response.ContentType = contenttype
        HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" & faFile)
        HttpContext.Current.Response.BinaryWrite(bytes)
        HttpContext.Current.Response.Flush()
        HttpContext.Current.Response.End()
        vRet = True
    Catch ex As Exception
        vRet = False
    Finally
        'doNothing
    End Try
    Return vRet
End Function 
 
»»»»»»»   by Santosh Kumar ?
Original @ http://santu4you.spaces.live.com
 

VB.Net, Reading text from most common document formats like .txt, .doc, .xls, .pdf and web pages like (.html, .aspx, .jsp, .php .etc)

 
Reading text from different files format may give directions to most of the challenges faced for building various tools like site search engine. Once you are able to extract texts, coding of very simple logic will be sufficient to design hundreds of web and window based tools. Here in this article, I am using itextsharp.dll apart from .NET and COM libraries. 
 
You need the following binaries. iTextSharp is a free binary. All other are from Miscrosoft and should be used as per Miscrosoft guidelines. If you have MS Office installed in you system you don't need these binaries. You can simply add COM reference of MS Word and MS Excel object libraries.
  
Interop.Excel.dll for .Net 2.0
(download attachment | download from original link)
 
Interop.Word.dll for .Net 2.0
(download attachment | download from original link)
 
Interop.Office.dll for .Net 2.0
(download attachment | download from original link)
 
Interop.VBIDE.dll for .Net 2.0
(download attachment | download from original link)
 
iTextSharp for .Net 2.0
(download attachment | download from original link)
 
'''''Code Begins herefrom 
 
Imports System.IO
Imports System.Data
Imports System.Xml
Imports System.Text
Imports System.Diagnostics
Imports Microsoft.VisualBasic
Imports System.Text.RegularExpressions
Imports iTextSharp.text.pdf
Imports System.Windows.Forms
 
Public Function ReadText_TXT(ByVal faPath As String) As String
    Dim vRet As String = ""
    Dim vStreamReader As StreamReader = File.OpenText(faPath)
    Try
        vRet = vStreamReader.ReadToEnd()
        vStreamReader.Close()
    Catch ex As Exception
        vRet = ""
    End Try
    Return vRet
End Function
 
Public Function ReadText_DOC(ByVal faPath As String) As String
    Dim vRet As String = ""
    Dim vRTB As New RichTextBox
    Dim vWD As New Word.Application
    vWD.Documents.Open(faPath)
    vWD.Selection.WholeStory()
    vWD.Selection.Copy()
    vRTB.Paste()
    vRet = vRTB.Text
    vWD.Quit()
    DoGarbageCollection(vWD)
    Return vRet
End Function
 
Public Function ReadText_XLS(ByVal faPath As String) As String
    Dim vRet As String = ""
    Dim vRTB As New RichTextBox
    Dim vXL As New Excel.Application
    Dim vWB As Excel.Workbook = Nothing
    Dim vWS As Excel.Worksheet = Nothing
    Dim vUR As Excel.Range = Nothing
    Dim vCnt As Integer
    Dim vCtr As Integer
    Dim vRow As Integer
    Dim vCol As Integer
    Dim vRows As Integer
    Dim vCols As Integer
    vWB = vXL.Workbooks.Open(faPath)
    vXL.Calculation = Excel.XlCalculation.xlCalculationManual
    vXL.AlertBeforeOverwriting = False
    vCnt = vWB.Worksheets.Count
 
    For vCtr = 1 To vCnt
        vWS = vWB.Worksheets(vCtr)
        vUR = vWS.UsedRange
        vRows = vUR.Rows.Count
        vCols = vUR.Columns.Count
        For vRow = 1 To vRows
            For vCol = 1 To vCols
                vRet = vRet & CType(vUR.Cells(vRow, vCol), Excel.Range).Value & " "
            Next vCol
        Next vRow
    Next
 
    vWB.Close(False)
    DoGarbageCollection(vWB)
    vXL.Quit()
    DoGarbageCollection(vXL)
 
    Return vRet
End Function
 
Public Function ReadText_PDF(ByVal faPath As String, Optional ByVal faFromPageNum As Integer = 0, _
    Optional ByVal faUptoPageNum As Integer = 0) As String
    Dim sb As New System.Text.StringBuilder()
    Try
        Dim reader As New PdfReader(faPath)
        Dim pageBytes() As Byte = Nothing
        Dim token As PRTokeniser = Nothing
        Dim tknType As Integer = -1
        Dim tknValue As String = String.Empty
        If faFromPageNum = 0 Then
            faFromPageNum = 1
        End If
        If faUptoPageNum = 0 Then
            faUptoPageNum = reader.NumberOfPages
        End If
        If faFromPageNum > faUptoPageNum Then
            Throw New ApplicationException("Err: faFromPageNum > faUptoPageNum")
        End If
 
        For i As Integer = faFromPageNum To faUptoPageNum Step 1
            pageBytes = reader.GetPageContent(i)
            If Not IsNothing(pageBytes) Then
                token = New PRTokeniser(pageBytes)
                While token.NextToken()
                    tknType = token.TokenType()
                    tknValue = token.StringValue
                    If tknType = PRTokeniser.TK_STRING Then
                        sb.Append(token.StringValue)
                    ElseIf tknType = 1 AndAlso tknValue = "-600" Then
                        sb.Append(" ")
                    ElseIf tknType = 10 AndAlso tknValue = "TJ" Then
                        sb.Append(" ")
                    End If
                    Application.DoEvents()
                End While
            End If
        Next i
        sb = New StringBuilder(sb.ToString)
    Catch ex As Exception
        Return String.Empty
 
    End Try
    Return sb.ToString()
End Function
 
Public Function ReadText_WEB(ByVal faUrl As String) As String
    Dim vRet As String = ""
    Try
        Dim vSNWebClient As System.Net.WebClient
        Dim vUTF8Encoding As UTF8Encoding
        vSNWebClient = New System.Net.WebClient()
        vUTF8Encoding = New UTF8Encoding()
        vRet = vUTF8Encoding.GetString(vSNWebClient.DownloadData(faUrl))
    Catch ex As Exception
        vRet = ""
    End Try
    Return ReadText_HTM(vRet)
End Function
 
Private Sub DoGarbageCollection(ByVal faObj As Object)
    Try
        Runtime.InteropServices.Marshal.ReleaseComObject(faObj)
    Catch
    Finally
        faObj = Nothing
    End Try
End Sub
 
Private Function ReadText_HTM(ByVal faContent As String) As String
    Dim vRet As String = faContent
    Try
        Dim vRegEx As Regex
        vRegEx = New Regex("", RegexOptions.IgnoreCase)
        vRet = Regex.Replace(vRet, "<(select|option|script|style|title)(.*?)>((.|\n)*?)</(select|option|script|style|title)>", " ", RegexOptions.IgnoreCase)
        vRet = Regex.Replace(vRet, "&(nbsp|quot|copy);", "")
        vRet = Regex.Replace(vRet, "<([\s\S])+?>", " ", RegexOptions.IgnoreCase)
        vRet = Regex.Replace(vRet, "\W", " ")
    Catch ex As Exception
        vRet = ""
    End Try
    Return Trim(vRet)
End Function
 
»»»»»»»   by Santosh Kumar ?
Original @ http://santu4you.spaces.live.com
 

VB.Net, Working with FTP

 
FTP Transfers files to and from a computer running a File Transfer Protocol (FTP) server service such as Internet Information Services. Ftp can be used interactively or in batch mode by processing ASCII text files. The following codes illustrates how to do the related operations programatically using VB.Net environment. 
 
Imports System.IO
Imports System.Net
 
Public Function doActionFTP_GetFileList( _
    ByVal FullFtpUrl As String,
    Optional ByVal Usr As String = "", _
    Optional ByVal Pwd As String = "" _
    ) As String
    Dim vDirList As String = ""
    Try
        Dim fwreqObj As FtpWebRequest = DirectCast(WebRequest.Create(FullFtpUrl), FtpWebRequest)
        fwreqObj.Method = WebRequestMethods.Ftp.ListDirectoryDetails
        fwreqObj.Credentials = New NetworkCredential(Usr, Pwd)
        Dim fwresObj As FtpWebResponse = DirectCast(fwreqObj.GetResponse(), FtpWebResponse)
        Dim srObj As New StreamReader(fwresObj.GetResponseStream, System.Text.Encoding.ASCII)
        vDirList = srObj.ReadToEnd
 
    Catch ex As Exception
        vDirList = ""
 
    End Try
    Return vDirList
End Function
 
Public Function doActionFTP_GetFileCrDate( _
    ByVal FullFtpUrl As String, _
    Optional ByVal Usr As String = "", _
    Optional ByVal Pwd As String = "" _
    ) As Date
    Dim fcDate As Date = Now
    Try
        Dim fwreqObj As FtpWebRequest = DirectCast(WebRequest.Create(FullFtpUrl), FtpWebRequest)
        fwreqObj.Method = WebRequestMethods.Ftp.GetDateTimestamp
        fwreqObj.Credentials = New NetworkCredential(Usr, Pwd)
        Dim fwresObj As FtpWebResponse = DirectCast(fwreqObj.GetResponse(), FtpWebResponse)
        fcDate = fwresObj.LastModified
 
    Catch ex As FileNotFoundException
        fcDate = DateValue("15-AUG-1947")
 
    Catch ex As Exception
        fcDate = DateValue("26-JAN-1951")
 
    End Try
    Return fcDate
End Function
 
Public Function doActionFTP_Upload( _
    ByVal FullFilePath As String, _
    ByVal FullFtpUrl As String, _
    Optional ByVal Usr As String = "", _
    Optional ByVal Pwd As String = "" _
    ) As Boolean
    Try
        Dim fwreqObj As FtpWebRequest = DirectCast(WebRequest.Create(FullFtpUrl), FtpWebRequest)
        fwreqObj.Method = WebRequestMethods.Ftp.UploadFile
        fwreqObj.Credentials = New NetworkCredential(Usr, Pwd)
 
        Dim byteObj As Byte() = File.ReadAllBytes(FullFilePath)
        fwreqObj.ContentLength = byteObj.Length
 
        Dim sObj As Stream = fwreqObj.GetRequestStream()
        sObj.Write(byteObj, 0, byteObj.Length)
        sObj.Close()
 
        Dim fwresObj As FtpWebResponse = DirectCast(fwreqObj.GetResponse(), FtpWebResponse)
        fwresObj.Close()
    Catch ex As Exception
        vRet = False
 
    Finally
     'do nothing
 
    End Try
    Return vret
End Function
 
Public Function doActionFTP_Dnload( _
    ByVal FullFtpUrl As String, _
    ByVal FullFilePath As String, _
    Optional ByVal Usr As String = "", _
    Optional ByVal Pwd As String = "" _
    ) As Boolean
    Dim vRet As Boolean = False
    Try
        Dim fwreqObj As FtpWebRequest = DirectCast(WebRequest.Create(FullFtpUrl), FtpWebRequest)
        fwreqObj.Method = WebRequestMethods.Ftp.DownloadFile
        fwreqObj.Credentials = New NetworkCredential(Usr, Pwd)
 
        Dim fwresObj As FtpWebResponse = DirectCast(fwreqObj.GetResponse(), FtpWebResponse)
        Dim sObj As Stream = fwresObj.GetResponseStream()
 
        Dim rObj As New StreamReader(sObj)
        Dim fsObj As New FileStream(FullFilePath, FileMode.Create)
        Dim wObj As New StreamWriter(fsObj)
 
        wObj.Write(rObj.ReadToEnd)
        wObj.Flush()
        wObj.Close()
        fsObj.Close()
        rObj.Close()
        sObj.Close()
        fwresObj.Close()
        vret = True
    Catch ex As Exception
        vRet = False
 
    Finally
     'do nothing
 
    End Try
    Return vret
End Function
 
»»»»»»»   by Santosh Kumar ? Original @ http://santu4you.spaces.live.com
 

Embedding google maps into web pages

 
Google Maps (for a time named Google Local) is a web mapping service application and technology provided by Google, free (for non-commercial use), that powers many map-based services, including the Google Maps website, Google Ride Finder, Google Transit, and maps embedded on third-party websites via the Google Maps API.
 
It offers street maps, a route planner for traveling by foot, car, or public transport and an urban business locator for numerous countries around the world.
 
According to one of its creators (Lars Rasmussen), Google Maps is "a way of organizing the world's information geographically"
 
Ref: http: //code.google.com/apis/maps/documentation/introduction.html
Ref: http: //en.wikipedia.org/wiki/Google_Maps
  
Sample Code
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
        <title>Google Maps JavaScript API Example: Simple Map</title>
        <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=abcdefg&sensor=true_or_false" type="text/javascript"></script>
        <script type="text/javascript">
            function initialize() {
                var map = new GMap2(document.getElementById("map_canvas"));
                map.setCenter(new GLatLng(20,77), 3);
                map.setUIToDefault();
            }
        </script>
    </head>
    <body onload="initialize()" onunload="GUnload()" leftmargin=0 rightmargin=0 topmargin=0 bottommargin=0>
        <div id="map_canvas" style="width: 600px; height: 450px"></div>
    </body>
</html>
 
 

JavaScript, Browser compatibility for getElementById

 
Browser detection is one of the most common scripting task that we face. The variety of different strategies in use for detecting browsers is unlimited. Here in this article I am not going to discuss it in details. Rather I am giving the following example that will help you to identified the HTML object independent of browsers. Instead of using the method getElementById in your javascript code you use getObjectById("elementname"). Please Find the following code
 
function getObjectByID(faObj){
    if (window.document[faObj])    {
        return window.document[faObj];
    }
    if (document.embeds[faObj]){
        return document.embeds[faObj];
    }
    if (document.getElementById(faObj)){
        return document.getElementById(faObj);
    }
}
 
»»»»»»»   by Santosh Kumar ? Original @ http://santu4you.spaces.live.com
 

Short Story ... Is your life worth saving?

 
A boy was drowning in a river and he shouted for help. A man passing by jumped in the river and saved the boy's life. As the man was leaving the boy said, Thank-you.'' The man asked, "For what?" The boy replied, "For saving my life."
 
The man looked into the boy's eyes and said,
 
"Upon, make sure when you grow up that your life was worth saving."
 
by Shiv Khera { You Can Win }
 

Short Story ... Meaningless goals

 
A farmer had a dog who used to sit by the roadside waiting for vehicles to come around. As soon as one came he would run down the road, barking and trying to overtake it. One day a neighbor asked the farmer "Do you think your dog is ever going to catch a car?" The farmer replied, "That is not what bothers me. What bothers me is what he would do if he ever caught one."
 
Many people in life behave like that dog who is pursuing meaningless goals.
 
by Shiv Khera { You Can Win }
 

Add-Ins Visible only to the user who installs Visual Basic

 
A user who has not installed Visual Basic cannot see any Add-Ins in the Add-In dialog in Visual Basic. The reason is that Visual Basic retrieves available Add-Ins based on the CurrentUser Settings in the Registry. To resolve the issue the Add-Ins need to be registered for each user. You can refer http://support.microsoft.com/?id=190212 for variously possibilities on registering add-ins. If you have installed Visual Basic / Visual Studio at its default location then you can try the following scripts. Either you copy these codes and paste into ms-dos command prompt or you can use it as a ms-dos batch file.
 
"%systemroot%\system32\regsvr32.exe" "%programfiles%\microsoft visual studio\vb98\Wizards\PDWizard\PDADDIN.DLL"
"%systemroot%\system32\regsvr32.exe" "%programfiles%\microsoft visual studio\vb98\Wizards\CTRLWIZ.DLL"
"%systemroot%\system32\regsvr32.exe" "%programfiles%\microsoft visual studio\vb98\Wizards\AXDOCWIZ.DLL"
"%systemroot%\system32\regsvr32.exe" "%programfiles%\microsoft visual studio\vb98\Wizards\AITOOL.DLL"
"%systemroot%\system32\regsvr32.exe" "%programfiles%\microsoft visual studio\vb98\Wizards\APPWIZ.OCX"
"%systemroot%\system32\regsvr32.exe" "%programfiles%\microsoft visual studio\vb98\Wizards\CLSSBLD.DLL"
"%systemroot%\system32\regsvr32.exe" "%programfiles%\microsoft visual studio\vb98\Wizards\DATAFORM.OCX"
"%systemroot%\system32\regsvr32.exe" "%programfiles%\microsoft visual studio\vb98\Wizards\MSDATOBJ.DLL"
"%systemroot%\system32\regsvr32.exe" "%programfiles%\microsoft visual studio\vb98\Wizards\PROPPGWZ.DLL"
"%systemroot%\system32\regsvr32.exe" "%programfiles%\microsoft visual studio\vb98\Wizards\RESEDIT.DLL"
"%systemroot%\system32\regsvr32.exe" "%programfiles%\microsoft visual studio\vb98\Wizards\TEMPMGR.DLL"
"%systemroot%\system32\regsvr32.exe" "%programfiles%\microsoft visual studio\vb98\Wizards\WIZMAN.DLL"
"%systemroot%\system32\regsvr32.exe" "%programfiles%\microsoft visual studio\Common\Tools\VCM\VCMMGR.DLL"
"%systemroot%\system32\regsvr32.exe" "%programfiles%\microsoft visual studio\Common\Tools\VS-Ent98\vmodeler\RVBADDIN.DLL"
"%systemroot%\system32\regsvr32.exe" "%programfiles%\microsoft visual studio\Common\Tools\VS-Ent98\vmodeler\RVBADDINMENUS.DLL"
"%systemroot%\system32\regsvr32.exe" "%programfiles%\microsoft visual studio\Common\Tools\VS-Ent98\vmodeler\RVBRESO.DLL"

»»»»»»»   by Santosh Kumar ? Original @ http://santu4you.spaces.live.com

Short Story ... Activity is Not the Same as Accomplishment


There is a big difference between activity and accomplishment. This was demonstrated by a French scientist named Fable. He conducted an experiment with processionary caterpillars. Caterpillars follow the one in front of them blindly. Fable arranged them in a circle in a flowerpot so that the lead caterpillar actually was behind the last one forming a circle. He put pine needles (food for the caterpillars) in the center of the flowerpot. The caterpillars kept going in a circle in the pot. Eventually, after a week of circling around, they dropped dead of exhaustion and starvation with food only inches away from them. We need to learn a lesson from the caterpillars. Just because you are doing something, doesn't mean you are getting anywhere. One must evaluate one's activity in order to have accomplishment.
 
A man was out driving with his wife and the wife said, "Honey, we are going the wrong way." The husband replied, "Who cares, we are making great time!" If we confuse activity with accomplishment, we could be making great time but we won't get anywhere.
 
by Shiv Khera { You Can Win }
 

Short Story ... Life is like a hot chocolate

 
A group of graduates, well established in their careers, were talking at a reunion and decided to go visit their old university professor, now retired.
 
During their visit, the conversation turned to complaints about stress in their work and lives.
 
Offering his guests hot chocolate, the professor went into the kitchen and returned with a large pot of hot chocolate and an assortment of cups - porcelain, glass, crystal, some plain looking, some expensive, some exquisite - telling them to help themselves to the hot chocolate.
 
When they all had a cup of hot chocolate in hand, the professor said: "Notice that all the nice looking, expensive cups were taken, leaving behind the plain and cheap ones. While it is normal for you to want only the best for yourselves, that is the source of your problems and stress.
 
The cup that you're drinking from adds nothing to the quality of the hot chocolate.. In most cases it is just more expensive and in some cases even hides what we drink.
 
What all of you really wanted was hot chocolate, not the cup; but you consciously went for the best cups... And then you began eyeing each other's cups.
 
LIFE IS THE HOT CHOCOLATE; YOUR JOB, MONEY AND POSITION IN SOCIETY ARE THE CUPS.
 
They are just tools to hold and contain life.
 
The cup you have does not define, nor change the quality of life you have.
 
Sometimes, by concentrating only on the cup, we fail to enjoy the hot chocolate God has provided us. God makes the hot chocolate, man chooses the cups. The happiest people don't have the best of everything. They just make the best of everything that they have.
 
Live simply. Love generously. Care deeply. Speak kindly. And enjoy your hot chocolate.
 
by Unknown
 

Embedding live music through live FM Radio

 
To embed media into web pages requires a player and a source file that is to be played. Incase of live multi-media resources it has to come through web-services. The code given here is streaming the media from punjabijunction.com and the plug-in is from microsoft.com. To listen the audios just click the play button if you have disabled the autostart features. It will start playing music from Radio City Live. And if you want the same at your web pages put this code into you HTML code.
 
<object id="MediaPlayer"
codeBase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112"
type="application/x-oleobject" height="50" standby="Loading Windows Media Player components..."
width="270" classid="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95">
    <param NAME="filename" VALUE="http://www.punjabijunction.com/ch_radiocity/RadioCity.asx">
    <param NAME="autoStart" VALUE="false">
    <param NAME="TransparentAtStart" VALUE="false">
    <param NAME="AnimationatStart" VALUE="false">
    <param NAME="ShowStatusBar" VALUE="true">
    <param NAME="ShowControls" VALUE="true">
    <param NAME="autoSize" VALUE="false">
    <param NAME="displaySize" VALUE="false">
    <param NAME="ShowAudioControls" VALUE="true">
    <param NAME="ShowPositionControls" VALUE="false">
    <embed type="application/x-mplayer2"
        pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/"
        src="http://www.punjabijunction.com/ch_radiocity/RadioCity.asx"
        width="270" height="50" transparentatstart="0" autostart="1" animationatstart="0"
        showcontrols="true" showaudiocontrols="1" showpositioncontrols="0" autosize="0"
        showstatusbar="1" displaysize="false"></embed>
</object> 
 
»»»»»»»   by Santosh Kumar ? Original @ http://santu4you.spaces.live.com

Short Story ... Why are Goals Important?

 
On the best sunny day, the most powerful magnifying glass will not light paper if you keep moving the glass. But if you focus and hold it, the paper will light up. That is the power of concentration.
 
A man was traveling and stopped at an intersection. He asked an elderly man, "Where does this road take me?" The elderly person asked, "Where do you want to go?" The 150 of 150 man replied, "I don't know." The elderly person said, "Then take any road. What difference does it make?"
 
How true. When we don't know where we are going, any road will take us there. Supposing you have the football eleven enthusiastically ready to play the game, all charged up, and then someone took the goal post away. What would happen to the game? There is nothing left. How do you keep score? How do you know you have arrived? Enthusiasm without direction is like wildfire and leads to frustration. Goals give a sense of direction.
 
Would you sit in a train or a plane without knowing where it was going? The obvious answer is no. Then why do people go through life without having any goals?
 
by Shiv Khera { You Can Win }
 

Asp.Net, Most useful binaries for working with .Net 2.0


Asp.Net 2.0 Ajax Extensions 1.0
(download attachment | download from original link)
 
Asp.Net Ajax enables developers to choose their preferred method of Ajax development, whether it is server-side programming, client-side programming, or a combination of both for building highly interactive and responsive web applications that work across all popular browsers. The UpdatePanels and a ScriptManager will solve all your partial post-back problems.
 
Asp.Net 2.0 Ajax Validators
(download attachment | download from original link)
 
Asp.Net 2.0 Ajax Extensions 1.0 has got some bugs while using validators. At first instant validation control will do its work but thereafter it won’t fire. Here we need the binary validators.dll. It also requires the following configurations in your web.config file.
 
<system.web>
    <pages>
    <controls>
        <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, 
        Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    </controls>
    <tagMapping>
        <add tagType="System.Web.UI.WebControls.CompareValidator"
        mappedTagType="Microsoft.Web.UI.Compatibility.CompareValidator, Validators"/>
        <add tagType="System.Web.UI.WebControls.CustomValidator"
        mappedTagType="Microsoft.Web.UI.Compatibility.CustomValidator, Validators"/>
        <add tagType="System.Web.UI.WebControls.RangeValidator"
        mappedTagType="Microsoft.Web.UI.Compatibility.RangeValidator, Validators"/>
        <add tagType="System.Web.UI.WebControls.RegularExpressionValidator"
        mappedTagType="Microsoft.Web.UI.Compatibility.RegularExpressionValidator, Validators"/>
        <add tagType="System.Web.UI.WebControls.RequiredFieldValidator"
        mappedTagType="Microsoft.Web.UI.Compatibility.RequiredFieldValidator, Validators"/>
        <add tagType="System.Web.UI.WebControls.ValidationSummary"
        mappedTagType="Microsoft.Web.UI.Compatibility.ValidationSummary, Validators"/>
    </tagMapping>
    </pages>
    ...
</system.web>
 
Asp.Net 2.0 AjaxControlToolkit
(download attachment | download from original link)
 
If you are not interested to write your own web user controls, this is where your struggle ends. Add a new tab to your toolbox and AjaxControlToolkit.dll will be included to your bin folder and then a number of Ajax control will be yours.
 
FusionCharts for Asp.Net
(download attachment | download from original link)
 
FusionCharts Enterprise Edition are really world-class solutions for web based charting solutions. It has been compatible with all the web technology and has got wider usage with PHP, ASP, .NET, JSP, ColdFusion, JavaScript, Ruby on Rails etc.
 
iTextSharp for .Net
(download attachment | download from original link)
 
It is the most useful free binary that provides most of the features you aspect for PDF files. Yes creation of PDF file from within a browser and Reading the text from the PDF file like of operations are nicely handled.
 
Winthusiasm HtmlEditor for Asp.Net 2.0
(download attachment | download from original link)
 
If you are looking for an Ajax enable HtmlEditor control then this is an answer to your search. Most of the required functionalities are covered here in this. It is much better than most of the paid version of such type of controls
 
MySql Connector for .Net 2.0
(download attachment | download from original link)
 
MySql is an answer to most of the database related challenges. From its existing MySql 5.1 onward it has been a headache for leading database solution providers. MySql.Data.dll 6.0.4 is the best solutions for your Asp.Net 2.0 applications. You can refer my article on its usage.
 
FlashControl for .Net 2.0
(download attachment | download from original link)
 
Embedding Flash / SWF object to any kind of web page is simple enough, but the challenge is to control these objects through server side scripts. FlashControl is the most useful dll to do such activity. Especially when you want to send some real-time data to flash object to set variables you will find these dll as most useful one. The property called FlashVars will be most attractive for you because you can then set multiple variables by setting values like "var1=value1&var2=value2&var3=value3" etc.

»»»»»»»   by Santosh Kumar ? Original @ http://santu4you.spaces.live.com