To Upload Documents in ASP.Net

Use the Following code to Validate and Upload files in ASP. Net


This Code Validates for the followings.
  • Only .doc, .docx, .ppt, .pptx, .xls, .xlsx, .pdf, .zip, .rtf, .jpg, .jpeg, .gif files can be Uploaded.
  • Filename must not exceed 100 characters (including extension).
  • Total Size of file (per Upload) must not exceed 10 MB.

Use "FileUpload" control to Upload the Doc.
In "web.config" set the following for size of the File allowed.
in "system.web" tag put the "httpRuntime" tag.
httpRuntime executionTimeout="300" maxRequestLength="102400"

Codings :
    Imports System.IO
    Imports System.Data.SqlClient

    Partial Class FileUpload
        Inherits System.Web.UI.Page

    #Region "Variables"
        Dim con As New SqlConnection
        Dim com As New SqlCommand
        Dim upldirinfo As DirectoryInfo
    #End Region

    #Region "Click on Upload"
        Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click
            Try
                If Page.IsValid Then
                    If ServerValidation() Then
                        Dim strftpPath1 As String = "C:\UploadFiles"
                        If FileUpload1.FileName.ToString <> "" Then
                            If strftpPath1 <> "" Then
                                upldirinfo = New DirectoryInfo(strftpPath1)
                                If Not upldirinfo.Exists Then
                                    upldirinfo.Create()
                                End If
                                Dim filename As String = FileUpload1.PostedFile.FileName
                                filename = filename.Remove(0, filename.LastIndexOf("\") + 1)
                                Dim filpath As String = strftpPath1 + "\" + filename
                                Dim filinfo As FileInfo
                                filinfo = New FileInfo(filpath)
                                If Not filinfo.Exists Then
                                    FileUpload1.PostedFile.SaveAs(strftpPath1 + "\" + filename)
                                    ClientScript.RegisterStartupScript(Me.GetType(), "onclick", "'<script language='javascript'>alert('" & filename & " is successfully Uploaded .');</script>")
                                    'DB Connection to Save the Deatils in Backend.
                                    con.ConnectionString = "Password=SSSS;Persist Security Info=True;User ID=SSSSSS;Initial Catalog=SSSSSSS;Data Source=SSSSSSSSS"
                                    con.Open()
                                    com.Connection = con
                                    com.CommandType = Data.CommandType.Text
                                    com.CommandText = "INSERT INTO tbFileUpload VALUES('" & strftpPath1 & "','" & filename & "')"
                                    com.ExecuteNonQuery()
                                Else
                                    ClientScript.RegisterStartupScript(Me.GetType(), "onclick", "<script language='javascript'>alert('The File Name " & filename & " already exists .');</script>")
                                End If
                            Else
                                ClientScript.RegisterStartupScript(Me.GetType(), "onclick", "<script language='javascript'>alert('Please Provide a Directory .');</script>")
                            End If
                        Else
                            ClientScript.RegisterStartupScript(Me.GetType(), "onclick", "<script language='javascript'>alert('Please you select a uploaded file .');</script>")
                        End If
                    End If
                End If
            Catch ex As Exception
                Throw ex
            End Try
        End Sub
    #End Region

    #Region "Code for ServerValidation"
        Public Function ServerValidation() As Boolean
            Try
                Dim size, intlen As Long 'Uploaded File Size
                Dim strExt1 As String 'Extension Type
                Dim retVal As Int16
                size = FileUpload1.PostedFile.ContentLength
                intlen = FileUpload1.FileName.LastIndexOf("\")
                retVal = FileUpload1.FileName.Substring(intlen + 1, FileUpload1.FileName.Length - intlen - 1).Length
                'getting uploaded file Extension Type
                If FileUpload1.HasFile Then
                    Dim strArr As String() = FileUpload1.FileName.Split(".")
                    strExt1 = strArr(strArr.Length - 1).ToLower
                End If
                'Checking Validation
                If Not FileUpload1.HasFile Then
                    ClientScript.RegisterStartupScript(Me.GetType(), "onclick", "<script language='javascript'>alert('Notification: Select files to upload.');</script>")
                    Return False
                ElseIf (FileUpload1.HasFile And FileUpload1.FileName.LastIndexOf(".") = -1) Then
                    ClientScript.RegisterStartupScript(Me.GetType(), "onclick", "<script language='javascript'>alert('Notification: Only .doc, .docx, .ppt, .pptx, .xls, .xlsx, .pdf, .zip, .rtf, .jpg, .jpeg, .gif files can be Uploaded.');</script>")
                    SetFocus(FileUpload1)
                    Return False
                ElseIf strExt1 <> "doc" And strExt1 <> "docx" And strExt1 <> "xls" And strExt1 <> "xlsx" And strExt1 <> "ppt" And strExt1 <> "pptx" And strExt1 <> "pdf" And strExt1 <> "zip" And strExt1 <> "rtf" And strExt1 <> "jpg" And strExt1 <> "jpeg" And strExt1 <> "gif" And strExt1 <> "" Then
                    ClientScript.RegisterStartupScript(Me.GetType(), "onclick", "<script language='javascript'>alert('Notification: Only .doc, .docx, .ppt, .pptx, .xls, .xlsx, .pdf, .zip, .rtf, .jpg, .jpeg, .gif files can be Uploaded.');</script>")
                    SetFocus(FileUpload1)
                    Return False
                ElseIf retVal > 100 Then
                    ' To Check File Name Length (100chars)
                    ClientScript.RegisterStartupScript(Me.GetType(), "onclick", "<script language='javascript'>alert('Notification: Filename must not exceed 100 characters (including extension).');</script>")
                    Return False
                ElseIf size > 10240000 Then 'Must not exceed 10 MB.
                    ClientScript.RegisterStartupScript(Me.GetType(), "onclick", "<script language='javascript'>alert('Notification: Total Size of file (per Upload) must not exceed 10 MB.');</script>")
                    Return False
                Else
                    Return True
                End If
            Catch ex As Exception
                Return False
                Throw ex
            End Try
        End Function
    #End Region

    #Region "Code for Clear the Text"
        Protected Sub btnClear_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClear.Click
            FileUpload1.Visible = True
        End Sub
    #End Region

    #Region "Code for Close"
        Protected Sub btnClose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClose.Click
            ClientScript.RegisterStartupScript(Me.GetType(), "onClick", "<script language='javascript'>window.close();</script>")
        End Sub
    #End Region

    End Class

Use Track Bar to Change the Font Size of the label Dynamically

Change the Font Size Dynamically of the Label by drag the Track Bar

Drag and drop one Label(Name - lblDisply) & one Track Bar
Then Write the coding in TrackBar1_Scroll() Event.


Code :
    Public Class frmUseTrackBar

        Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
            lblDisply.Font = New System.Drawing.Font("Microsoft Sans Serif", (9 + CType(TrackBar1.Value, Double)), System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            ' 9 + CType(TrackBar1.Value, Double) : 9 - For Intial Font Size. TrackBar1.Value - Increase the Font size using this value
        End Sub

    End Class

World Ocean or Global Ocean

World Ocean or Global Ocean

There are 5 World Ocean or Global Ocean in the World.
  1. Arctic Ocean
  2. Atlantic Ocean
  3. Indian Ocean
  4. Pacific Ocean
  5. Southern Ocean

Continents in the World.

CONTINENTS

There are 7 Continents in the World.

NameArea in Square KM% of Earth's AreaHighest Point in meters[sea-level]Lowest Point in meters[sea-level]
Asia43,998,00029.5Everest [8848]Dead Sea [-396.8]
Africa29,800,00020.0Kilimanjaro [5894]Dead Sea [-156.1]
North America21,510,00016.3McKinely [6194]Death Valley [-85.9]
South America17,598,00011.8Aconcagua [6960]Valdes Penin [-39.9]
Europe9,699,5506.5Elbrus [5663]Caspian Sea [-28.0]
Australia7,699,0005.2Kosciusko [2228]Lake Eyre [-15.8]
Antarctica13,600,0009.6Vinson Massif [5140]Bentley Subglacial Trench[-2,538]

Indian States, their Capitals & Languages used


INDIAN STATES


India is a federal union of states comprising 28 states.
Following are the States, their Capitals & Languages used .

StatesCapitalLanguages
Andra PradeshHyderabadTelugu and Urdu
Arunachal PradeshItanagerMiji, Apotanji, Merdukpen, Tagin,Adi, Honpa, Bangini-Nishi.
AssamDispurAssamese
Bihar PatnaHindi
ChhattisgarhRaipurHindi
GoaPanajiMarathi and Konkani
GujaratGandhinagarGujarati
HaryanaChandigarhHindi
Himachal PradeshShimlaHindi and Pahari
MizoramAizawlMizo and English
Jammu & KashmirSrinagar (Summer)
Jammu (Winter)
Kashmiri,Dogri, Urdu, Ladakhi,
Pahari,Punjabi and Dadri
JharkhandRanchiHindi
KarnatakaBangaloreKannda
KeralaTrivandrumMalayalam
Madhya PradeshBhopalHindi
MaharashtraBombayMarathi
ManipurImphalManipuri
MeghalayaShillongKhasi, Jaintia and Garo
NagalandKohimaAo, Konyak, Angami, Sema and Lotha
OrissaBhubaneswarOriya
PunjabChandigarhPunjabi
RajasthanJaipurRajasthani and Hindi
SikkimGangtokBhutia, Hindi, Nepali, Lepcha, Limbu
Tamil NaduChennaiTamil
TripuraAgartalaBengali, Tripuri, Manipuri, Kakborak
Uttar PradeshLucknowHindi
UttaranchalDehra DunHindi
West BengalCalcuttaBengali

Encrypt OR Decrypt a String Using ASCII Character in Dot Net.

Using this we can Encrypt OR Decrypt a String for security Purpose.
Using this we can EnCrypt the password & save in Back end. Then while retrieving again we can Decrypt the password.


Code :
    Public Class frmEnCryptDeCrypt

    #Region "btnEnCryptDeCrypt Click"
        Private Sub btnEnCryptDeCrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnCryptDeCrypt.Click
            txtResult.Text = fnEnCryptDeCrypt(txtInput.Text)
        End Sub
    #End Region

    #Region "EnCrypt or DeCrypt String"
        Public Function fnEnCryptDeCrypt(ByVal Text As String) As String
            Dim strTempChar As String = "", i As Integer
            For i = 1 To Len(Text)
                If Asc(Mid$(Text, i, 1)) < strtempchar = " CType(Asc(Mid$(Text," > 128 Then
                    strTempChar = CType(Asc(Mid$(Text, i, 1)) - 128, String)
                End If
                Mid$(Text, i, 1) = Chr(CType(strTempChar, Integer))
            Next i
            Return Text
        End Function
    #End Region

    End Class