This is a migrated thread and some comments may be shown as answers.

How to determine name of files via RadUpload1.UploadedFiles

1 Answer 79 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Joe
Top achievements
Rank 2
Joe asked on 09 Dec 2008, 04:08 PM
I am using the following code:

For Each f As UploadedFile In RadUpload1.UploadedFiles  
 
            Dim targetFolder As String = Session("UserDir")  
            Dim targetFileName As String = System.IO.Path.Combine(targetFolder, f.GetName)  
 
            If System.IO.File.Exists(targetFileName) Then 
                'Sets error label to visable and displays message.  
                lblUploadError1.Visible = True 
                lblUploadError1.Text = "File name " & f.GetName & " already exists!" 
            Else 
            'Save uploaded file(s) info to database  
 End Using
End IF
Next
 

The problem is that I want to display an error message for any of the 5 possible uploaded files by changing the lblUploadError1.Text thru lblUplaodError5.Text

So somehow I need to associate the f.GetName with each of the files that were uploaded.

Any suggestions?

Thanks,
Joe

1 Answer, 1 is accepted

Sort by
0
Joe
Top achievements
Rank 2
answered on 09 Dec 2008, 07:15 PM
Ok, I'm on a role today.... I've figured this one out too... Here's the final code. If anyone has a better, more elegent solution, please let me know.

Imports Telerik.Web.UI  
Imports System.IO  
Imports System.Data.SqlClient  
Imports Telerik.Web.UI.Upload  
 
Protected Sub SubmitButton_Click(ByVal sender As ObjectByVal e As System.EventArgs) Handles SubmitButton.Click  
        'Set target directory path to user's directory  
        'RadUpload1.TargetPhysicalFolder = Session("userDir")  
 
        If RadUpload1.UploadedFiles.Count > 0 Then 
            System.Threading.Thread.Sleep(3000)  
        End If 
 
        For Each f As UploadedFile In RadUpload1.UploadedFiles  
 
            Dim targetFolder As String = Session("UserDir")  
            Dim targetFileName As String = System.IO.Path.Combine(targetFolder, f.GetName)  
 
            If System.IO.File.Exists(targetFileName) Then 
                'Sets error label to visible and displays message.  
                lblUploadError.Visible = True 
                lblUploadError1.Visible = True 
                'This add's all the preexisting file names to the label  
                lblUploadError1.Text = lblUploadError1.Text & f.GetName & ", " 
            Else 
                f.SaveAs(Session("UserDir") & f.GetName, False)  
 
                ' Insert a new record into Call_Info table  
 
                'Set Active Date on new user to today  
                Dim UploadDate As DateTime = DateTime.Now  
 
                Dim connectionString As String = ConfigurationManager.ConnectionStrings("eonPortalCS").ConnectionString  
                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)" 
                Dim myConnection As New System.Data.SqlClient.SqlConnection(connectionString)  
                Dim myCommand As New System.Data.SqlClient.SqlCommand(insertSql, myConnection)  
                Using myConnection  
                    myConnection.Open()  
                    myCommand.Parameters.AddWithValue("@UserId", Session("UploadUserID"))  
                    myCommand.Parameters.AddWithValue("@FileName", f.GetName)  
                    myCommand.Parameters.AddWithValue("@FileLocation", Session("UserDir"))  
                    myCommand.Parameters.AddWithValue("@Discipline", Session("UserDiscipline"))  
                    myCommand.Parameters.AddWithValue("@CallStatus""New")  
                    myCommand.Parameters.AddWithValue("@UploadDate", UploadDate)  
                    myCommand.Parameters.AddWithValue("@UploadedBy", Session("CurrentUserGuid"))  
                    myCommand.ExecuteNonQuery()  
                    myConnection.Close()  
                End Using  
            End If 
        Next 
        RadUpload1.Enabled = False 
        SubmitButton.Enabled = False 
        Session("UploadUserID") = "" 
 
    End Sub 

Thanks,
Joe
Tags
Upload (Obsolete)
Asked by
Joe
Top achievements
Rank 2
Answers by
Joe
Top achievements
Rank 2
Share this question
or