1 |
Imports Telerik.Web.UI |
2 |
Imports System.IO |
3 |
Imports System.Data.SqlClient |
4 |
Imports Telerik.Web.UI.Upload |
5 |
|
6 |
Protected Sub RadUpload1_FileExists(ByVal sender As Object, ByVal e As UploadedFileEventArgs) Handles RadUpload1.FileExists |
7 |
Dim file As UploadedFile = e.UploadedFile |
8 |
'Session("UserDir") comes from other working code |
9 |
Dim targetFolder As String = Session("UserDir") |
10 |
Dim targetFileName As String = System.IO.Path.Combine(targetFolder, file.GetExtension) |
11 |
|
12 |
While System.IO.File.Exists(targetFileName) |
13 |
'Sets error label to visable and displays message. |
14 |
lblUploadError.Visible = True |
15 |
lblUploadError.Text = "File name already exists!" |
16 |
End While |
17 |
End Sub |
18 |
|
19 |
Protected Sub SubmitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SubmitButton.Click |
20 |
|
21 |
If RadUpload1.UploadedFiles.Count > 0 Then |
22 |
System.Threading.Thread.Sleep(3000) |
23 |
End If |
24 |
|
25 |
For Each f As UploadedFile In RadUpload1.UploadedFiles |
26 |
f.SaveAs(Session("UserDir") & f.GetName, False) |
27 |
|
28 |
' Insert a new record into Call_Info table |
29 |
|
30 |
'Set Active Date on new user to today |
31 |
Dim UploadDate As DateTime = DateTime.Now |
32 |
|
33 |
Dim connectionString As String = ConfigurationManager.ConnectionStrings("eonPortalCS").ConnectionString |
34 |
Dim insertSql As String = "INSERT INTO Call_Info(UserId, File_Name, File_Location, Discipline, Call_Status, Upload_Date, Uploaded_By) VALUES(@UserId, @FileName, @FileLocation, @Discipline, @CallStatus, @UploadDate, @UploadedBy)" |
35 |
Dim myConnection As New System.Data.SqlClient.SqlConnection(connectionString) |
36 |
Dim myCommand As New System.Data.SqlClient.SqlCommand(insertSql, myConnection) |
37 |
|
38 |
Using myConnection |
39 |
myConnection.Open() |
40 |
myCommand.Parameters.AddWithValue("@UserId", Session("UploadUserID")) |
41 |
myCommand.Parameters.AddWithValue("@FileName", f.GetName) |
42 |
myCommand.Parameters.AddWithValue("@FileLocation", Session("UserDir")) |
43 |
myCommand.Parameters.AddWithValue("@Discipline", Session("UserDiscipline")) |
44 |
myCommand.Parameters.AddWithValue("@CallStatus", "New") |
45 |
myCommand.Parameters.AddWithValue("@UploadDate", UploadDate) |
46 |
myCommand.Parameters.AddWithValue("@UploadedBy", Session("CurrentUserGuid")) |
47 |
myCommand.ExecuteNonQuery() |
48 |
myConnection.Close() |
49 |
End Using |
50 |
Next |
51 |
RadUpload1.Enabled = False |
52 |
SubmitButton.Enabled = False |
53 |
Session("UploadUserID") = "" |
54 |
End Sub |
55 |
|