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

Manipulating selectedFiles collection - remove files

3 Answers 48 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Craig
Top achievements
Rank 1
Craig asked on 10 Nov 2011, 01:01 AM
Is there a way to remove selected files from the selectedfiles collection, certain files, not all?

Ideally I would like to remove them as soon as they are added or don't add them to the collection at all.

I am validating some things and don't want the files added to the selection. I know I can cancel the upload of the file but that happens to late in my process. I need to remove them from the collection before the upload so they can add them again if that makes any sense.

Example. The user browses for 3 files and selects open, I then check certain things about the file, is there an associated country or state selected. If it does not meet the requirements then I want to remove it from the selected files collection so they can change certain things and then try to add it again.









3 Answers, 1 is accepted

Sort by
0
Craig
Top achievements
Rank 1
answered on 10 Nov 2011, 05:42 PM
BTW we did pay for Priority Support. Advantage Content Partners.

Thanks,
Craig
0
Craig
Top achievements
Rank 1
answered on 11 Nov 2011, 02:03 AM
Okay I got most of what I am trying to achieve working. I can handle keeping the uploader in sync with the grid and it works fine. I have successfully added items to the selectedfiles collection and that works fine.

The problem I am having now is after I cancel a particular file by adding the handler for validating.

It executes the onvalidate procedure, and it successfully cancels the upload for the file in question and uploads all other files.

I am adding the canceled file to a filesUnchecked As New List(Of FileInfo)().

All that seems to work perfectly.

Then in the upload finished event I create some XML and other stuff and try to add the items from files unchecked list back into the current session.

It doesn't seem to add the files back to currentsession.selecteditems. I don't get an upload option and the file does not appear to be added to the collection allthough  

Here is the code.

When upload is finished I for sure have the canceled files in the unchecked list and it appears to add them to the collection with the reupload items sub but but doesn't.

No error messages of any kind.

Dim filesUnchecked As New List(Of FileInfo)()


RadUpload1.AddHandler(RadUploadItem.ValidateEvent, New UploadValidateEventHandler(AddressOf OnValidate))

Private Sub OnValidate(ByVal sender As Object, ByVal e As UploadValidateEventArgs)

        For Each row In dtImageCollection.Rows

            Dim strRowfilename As String

            strRowfilename = (row("FILE_NAME") & "." & row("EXTENSION"))

            files.Clear()

            For Each item In RadUpload1.CurrentSession.SelectedFiles

                files.Add(item.File)

            Next

            If TryCast(e.OriginalSource, RadUploadItem).FileName.Equals(strRowfilename) Then

                If row("CHECKED") = False Then

                    For Each File In files

                        If strRowfilename = File.Name Then

                            e.Cancel = True

                            filesUnchecked.Add(File)

                            Exit For

                        End If

                    Next

                End If

            End If

        Next

End Sub

Private Sub RadUpload1_UploadFinished(ByVal sender As Object, ByVal e As RoutedEventArgs)

        Dim ws As New wsMultiSelectServiceClient()

        For Each row In dtImageCollection.Rows

            If row("CHECKED") = True Then

                Dim sXML As String = "<TOKOPEN>" & _
                                        "<REQUEST>" & _
                                            "<ACTION>ADD DOCUMENT</ACTION>" & _
                                            "<DRAWER>Projects</DRAWER>" & _
                                            "<DOCTYPE>" & row!DOCTYPE & "</DOCTYPE>" & _
                                        "<INDICES>" & _
                                            "<COUNTRY>" & row!COUNTRY & "</COUNTRY>" & _
                                            "<STATE>" & row!STATE & "</STATE>" & _
                                            "<COUNTY>" & row!COUNTY & "</COUNTY>" & _
                                            "<DRILLINGAREA>" & row!DRILLING_AREA & "</DRILLINGAREA>" & _
                                            "<BLOCK>" & row!TEMP & "</BLOCK>" & _
                                            "<OPERATOR>" & row!OPERATOR & "</OPERATOR>" & _
                                            "<WELLNAME>" & row!WELL_NAME & "</WELLNAME>" & _
                                            "<SPUDDATE>" & row!SPUD_DATE & "</SPUDDATE>" & _
                                            "<HOLESIZE>" & row!HOLE_SIZE & "</HOLESIZE>" & _
                                            "<BITSIZE>" & row!BIT_SIZE & "</BITSIZE>" & _
                                            "<JOBID>" & row!JOB_ID & "</JOBID>" & _
                                            "<UPLOADEDBY>" & sUserName & "</UPLOADEDBY>" & _
                                            "<AUTHOR>" & row!AUTHOR & "</AUTHOR>" & _
                                            "<DocDescription>" & DeNull(row!FILE_NAME) & "." & DeNull(row!EXTENSION) & "</DocDescription>" & _
                                            "<SUBFOLDER>" & row!PROD_LINE & "</SUBFOLDER>" & _
                                        "</INDICES>" & _
                                        "<SOURCE>" & _
                                            "<FILE>" & row!FILE_NAME & "." & DeNull(row!EXTENSION) & "</FILE>" & _
                                        "</SOURCE>" & _
                                         "<CREATEDBY>Upload Service</CREATEDBY>" & _
                                        "</REQUEST>" & _
                                        "<EXTRADATA>" & _
                                            "<HASHDIR />" & _
                                            "<SOURCEDIR>" & Savetodirectory & "</SOURCEDIR>" & _
                                        "</EXTRADATA>" & _
                                    "</TOKOPEN>"

        Dim i As Integer
        'Leave selected files in the grid.
        For i = 0 To dtImageCollection.Rows.Count - 1

            If dtImageCollection.Rows.Count = 0 Then
                Exit For

            End If

            If i > dtImageCollection.Rows.Count - 1 Then

                Exit For

            End If

            If dtImageCollection.Rows(i)("CHECKED") = True Then

                dtImageCollection.Rows.RemoveAt(i)

                i = i - 1

            End If

        Next

RadUpload1.CurrentSession.SelectedFiles.Clear()

Me.Dispatcher.BeginInvoke(Function() New Action(AddressOf ReUploadItems))

RadUpload1.PrepareSelectedFilesForUpload()

        RadGridView1.Rebind()

End Sub

Private Sub ReUploadItems()

        For Each item In filesUnchecked

            Dim f As New RadUploadSelectedFile(item)
            RadUpload1.CurrentSession.SelectedFiles.Add(f)

        Next


End Sub


0
Alex Fidanov
Telerik team
answered on 14 Nov 2011, 04:35 PM
Hello Craig,

Thank you for providing the code snippet that you are using. What I noticed is that you are calling the ReUploadItems method (in a Dispatcher) in which you are re-adding the unchecked items. The line that follows is the Prepare selected files for upload method.

Calling it from a dispatcher will execute it async and with a little delay. The PrepareSelectedFilesForUpload method will most likely run before the Action in the dispatcher executes and therefore will not prepare any files. What I would suggest, i moving the PrepareSelectedFilesForUpload inside the ReUploadItems method, after the foreach loop. This will ensure that the files are prepared right after they have been added to the upload control.

Kind regards,
Alex Fidanov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
Upload
Asked by
Craig
Top achievements
Rank 1
Answers by
Craig
Top achievements
Rank 1
Alex Fidanov
Telerik team
Share this question
or