frm upload

3
frmUpload.aspx.vb Imports System.IO.File Imports System.IO Imports System.Collections Imports System.Data.SqlClient Public Class frmUpload Inherits System.Web.UI.Page Protected WithEvents REMOVEFILE As System.Web.UI.WebControls.ImageButton Protected WithEvents ADDFILE As System.Web.UI.WebControls.ImageButton Protected WithEvents DONE As System.Web.UI.WebControls.ImageButton Protected WithEvents lstUpload As System.Web.UI.WebControls.ListBox Protected WithEvents lblMessage As System.Web.UI.WebControls.Label Protected WithEvents fileupload As System.Web.UI.HtmlControls.HtmlInputFile 'Shared byteCnt As Int64 Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not IsPostBack Then If Not Session("hashTableFiles") Is Nothing Then If Session("hashTableFiles").Count > 0 Then Dim keyCollection As DictionaryEntry Dim str As String Dim splitFileName(), splitKey() As String 'keyCollection = Session("hashTableFiles").Keys() For Each keyCollection In Session("hashTableFiles") 'str = keyCollection.Key.ToString() splitKey = Split(keyCollection.Key, "-") 'If str.Substring(0, 3) = Request("FormName") Then If splitKey(0) = Request("FormName") And splitKey(1) = Request("iID") Then splitFileName = Split(keyCollection.Value.PostedFile.FileName.ToString(), "\") lstUpload.Items.Add(splitFileName(splitFileName.GetUpperBound(0))) lstUpload.Items(lstUpload.Items.Count - 1).Value = keyCollection.Key.ToString() End If Next End If End If End If End Sub Private Sub ADDFILE_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ADDFILE.Click Dim hashTableFiles As Hashtable Dim splitFileName(), Str() As String Dim keyCollection As DictionaryEntry Dim byteCnt As Int64 byteCnt = 0 If fileupload.PostedFile.FileName <> "" Then If Session("hashTableFiles") Is Nothing Then hashTableFiles = New Hashtable() Session("hashTableFiles") = hashTableFiles End If For Each keyCollection In Session("hashTableFiles") Str = Split(keyCollection.Key.ToString(), "-") If Str(1) = Request("iID") Then If byteCnt = 0 Then byteCnt = keyCollection.Value.PostedFile.ContentLength() Else byteCnt = byteCnt + Page 1

Upload: singamroopa

Post on 13-Feb-2016

3 views

Category:

Documents


0 download

DESCRIPTION

Frm Upload

TRANSCRIPT

Page 1: Frm Upload

frmUpload.aspx.vbImports System.IO.FileImports System.IOImports System.CollectionsImports System.Data.SqlClientPublic Class frmUpload Inherits System.Web.UI.Page Protected WithEvents REMOVEFILE As System.Web.UI.WebControls.ImageButton Protected WithEvents ADDFILE As System.Web.UI.WebControls.ImageButton Protected WithEvents DONE As System.Web.UI.WebControls.ImageButton Protected WithEvents lstUpload As System.Web.UI.WebControls.ListBox Protected WithEvents lblMessage As System.Web.UI.WebControls.Label Protected WithEvents fileupload As System.Web.UI.HtmlControls.HtmlInputFile 'Shared byteCnt As Int64

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not IsPostBack Then If Not Session("hashTableFiles") Is Nothing Then If Session("hashTableFiles").Count > 0 Then Dim keyCollection As DictionaryEntry Dim str As String Dim splitFileName(), splitKey() As String 'keyCollection = Session("hashTableFiles").Keys() For Each keyCollection In Session("hashTableFiles") 'str = keyCollection.Key.ToString() splitKey = Split(keyCollection.Key, "-") 'If str.Substring(0, 3) = Request("FormName") Then If splitKey(0) = Request("FormName") And splitKey(1) = Request("iID") Then splitFileName = Split(keyCollection.Value.PostedFile.FileName.ToString(), "\")

lstUpload.Items.Add(splitFileName(splitFileName.GetUpperBound(0)))

lstUpload.Items(lstUpload.Items.Count - 1).Value = keyCollection.Key.ToString() End If Next End If End If End IfEnd Sub

Private Sub ADDFILE_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ADDFILE.Click Dim hashTableFiles As Hashtable Dim splitFileName(), Str() As String Dim keyCollection As DictionaryEntry Dim byteCnt As Int64 byteCnt = 0 If fileupload.PostedFile.FileName <> "" Then If Session("hashTableFiles") Is Nothing Then hashTableFiles = New Hashtable() Session("hashTableFiles") = hashTableFiles End If For Each keyCollection In Session("hashTableFiles") Str = Split(keyCollection.Key.ToString(), "-") If Str(1) = Request("iID") Then If byteCnt = 0 Then byteCnt = keyCollection.Value.PostedFile.ContentLength() Else byteCnt = byteCnt +

Page 1

Page 2: Frm Upload

frmUpload.aspx.vbkeyCollection.Value.PostedFile.ContentLength() End If End If Next If byteCnt = 0 Then byteCnt = fileupload.PostedFile.ContentLength() Else byteCnt = byteCnt + fileupload.PostedFile.ContentLength End If If byteCnt > 1024000 Then lblMessage.Text = "File Size cannot be greater 1MB" Else

Session("hashTableFiles").Add(IsKeyExist(Request("FormName"), Session("hashTableFiles").Count, Request("iID")), fileupload) splitFileName = Split(fileupload.PostedFile.FileName, "\")

lstUpload.Items.Add(splitFileName(splitFileName.GetUpperBound(0))) lstUpload.Items(lstUpload.Items.Count - 1).Value = Request("FormName") & Session("hashTableFiles").Count lblMessage.Text = "" End If End If End Sub

Private Function IsKeyExist(ByVal Key As String, ByVal count As Integer, ByVal iID As String) As String If Session("hashTableFiles").ContainsKey(Key & "-" & iID & "-" & count) = True Then Key = IsKeyExist(Key, count + 1, iID) Else Key = Key & "-" & iID & "-" & count End If Return KeyEnd Function

Private Sub REMOVEFILE_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles REMOVEFILE.Click If lstUpload.SelectedIndex >= 0 Then Session("hashTableFiles").Remove(lstUpload.SelectedItem.Value) lstUpload.Items.RemoveAt(lstUpload.SelectedIndex) End IfEnd Sub

Private Sub DONE_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles DONE.Click If Not Session("hashTableFiles") Is Nothing Then If Session("hashTableFiles").Count > 0 Then Dim keyCollection As DictionaryEntry Dim str As String Dim splitFileName() As String Dim cntr As Integer Dim oleDBConnect As OleDb.OleDbConnection Dim oleDBCmd, oleDBCmd1 As OleDb.OleDbCommand Dim strQuery As String cntr = 0 oleDBConnect = New OleDb.OleDbConnection("Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=QSv2;Data Source=teechee\teechee;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=TEECHEE;Use Encryption for Data=False;Tag with column collation when possible=False") oleDBConnect.Open() For Each keyCollection In Session("hashTableFiles")

Page 2

Page 3: Frm Upload

frmUpload.aspx.vb str = keyCollection.Key.ToString() If str.Substring(0, 3) = "Upl" Then splitFileName = Split(keyCollection.Value.PostedFile.FileName, "\")

keyCollection.Value.PostedFile.SaveAs(Server.MapPath("\Qsv2\CandidateDirectories\" &Request("CaseRefNo") & "\" & splitFileName(splitFileName.GetUpperBound(0)))) strQuery = "Select FileN from CandidateReport where FileN='" & splitFileName(splitFileName.GetUpperBound(0)) & "'" oleDBCmd = New OleDb.OleDbCommand(strQuery, oleDBConnect) If oleDBCmd.ExecuteReader().Read = False Then oleDBConnect.Close() oleDBConnect.Open() strQuery = "Insert into CandidateReport (CandidateID,DocumentPath,FileN) values(" & Request("CandidateID") &",'" & Server.MapPath("\Qsv2\CandidateDirectories\" & Request("CaseRefNo") & "\" & splitFileName(splitFileName.GetUpperBound(0))) & "','" & splitFileName(splitFileName.GetUpperBound(0)) & "')" oleDBCmd1 = New OleDb.OleDbCommand(strQuery, oleDBConnect) oleDBCmd1.ExecuteNonQuery() oleDBCmd1.Dispose() oleDBCmd1 = Nothing End If

oleDBCmd.Dispose() oleDBCmd = Nothing

cntr = cntr + 1 End If Next End If End If Response.Redirect("frmUploadReport.aspx") End SubEnd Class

Page 3