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

System.NullReferenceException Telerik.Windows.Controls.RadUpload.ShowValidFiles()

4 Answers 79 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Jonx
Top achievements
Rank 2
Jonx asked on 09 Dec 2010, 04:14 AM
Hello,
I try to use the RadUpload control programaticaly.

Do you mind showing a detailed exemple of how to correctly achieve this?

Your help page does not tell much.
http://www.telerik.com/help/silverlight/radupload-features-programmatic-upload.html
(by the way, the page talks about HasItems that has beend removed in the latest builds)

My code is the following:
private void btnImport_Click(object sender, RoutedEventArgs e)
{
        FileImport.ShowFileDialog();
        if (FileImport.Items.Count > 0)
        {
            FileImport.StartUpload();
        }
}

When I do that everything works fine the first file upload.
The second time I select a file I get the following exception:
System.NullReferenceException Telerik.Windows.Controls.RadUpload.ShowValidFiles()

This is not cool. I get stuck every here and there just because the doc does not tell much despite the component being excellent...

Thanks to that other thread:
http://www.telerik.com/community/forums/silverlight/upload/removing-files-from-items-array-doesn-t-work-properly.aspx
I had the intuition to clear the Items list. This does not seem logical to me or at least it should be made clear somewhere that tis is happening. Why is this needed? Because anyway I'll be unable to upload the same file twice. Right?

Here in that other thread:
http://www.telerik.com/community/forums/silverlight/upload/overwrite-upload-question.aspx
I see that the guys clears much more then I do:
radUpload1.CurrentSession.FailedFiles.Clear();
//radUpload1.CurrentSession.SelectedFiles.Clear();
radUpload1.CurrentSession.UploadedFiles.Clear();
radUpload1.CurrentSession.ValidFiles.Clear();
radUpload1.Items.Clear();

1/ Is this needed for me? Should I clear all those lists when using the control programatically?

2/ Shall I take care of those lists when using the control in the normal way?

Would you please update the documentation accordingly or point to the place I can find the correct info?

Thans a lot in advance.
John.


4 Answers, 1 is accepted

Sort by
0
Alex Fidanov
Telerik team
answered on 09 Dec 2010, 10:40 AM
Hello John,

I apologize for the inconveniences. Regarding the NullReferenceException, we have already resolved that with the internal builds. Please re-test this with the latest internal build and let us know if the problem is resolved on your end. This was a side product of the major refactoring on the UI related code that we did for Q3. Moreover, we have improved using the control in procedural code only. We have created a new method "PrepareSelectedFilesForUpload" which will take care of the cleaning for you. Here is a small sample code for this :

// add some files in the RadUpload.CurrentSession.SelectedFiles :
foreach (FileInfo file in files)
{
    RadUploadSelectedFile f = new RadUploadSelectedFile(file);
    this.upload.CurrentSession.SelectedFiles.Add(f);
}
// prepare files for upload :
this.upload.OverwriteExistingFiles = true;
this.upload.PrepareSelectedFilesForUpload();
// start upload :
this.upload.StartUpload();
We will also update the help article, thank you for pointing this out.

Let me know if you still have issues with this matter.

Best wishes,
Alex Fidanov
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Jonx
Top achievements
Rank 2
answered on 10 Dec 2010, 03:43 AM
Hello Alex,
Thank you for your sample but sorry to say I do not understand how this does integrate with my scenario.

I'm using the FileImport.ShowFileDialog();
I guess this is already building the file list correctly for me, no?

My code is the following:
private void btnImport_Click(object sender, RoutedEventArgs e)
{
        FileImport.ShowFileDialog();
                      FileImport.Items.Clear();
        if (FileImport.Items.Count > 0)
        {
            FileImport.StartUpload();
        }
}

This is working right now.

Are you telling me I should replace that with your code?
Where in your code do you select the files?
Can you correct my sample to illustrate your thought please?
Thanks a lot in advance,
John.
0
Accepted
Alex Fidanov
Telerik team
answered on 10 Dec 2010, 09:54 AM
Hello John,

The new valid file items are being created in the ShowValidFiles() method, which was throwing the NRE. This was happening only in cases where the RadUpload is collapsed, the items were collapsed or used only from procedural code. You code is correct and it should be working as expected with the latest internal builds. My code snippet relates to scenarios where files are being added in the RadUpload not through the OpenFileDialog, which is not your case, but it is still good to know if you have this scenario.

Greetings,
Alex Fidanov
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Jonx
Top achievements
Rank 2
answered on 10 Dec 2010, 05:25 PM
Ok, good to know...

Thank your for all the details.

As for the test with the internal builds, I'm not going to make the test sorry.
I'm very reluctant to instant a new build for the moment as I hard a very hard time getting things right again after having installed Q3 side by side with Q2 and an intermediate build. It took me so long to get everything in order again and at this end I had to remove everything, clear the toolbox items by hand and instal everything again. You new tool to switch toolbar version does not work at all for me :( 

Anyway, I'll make the switch with the next official build and let you know.

Thanks again,
It's working fine for now.
John.
Tags
Upload
Asked by
Jonx
Top achievements
Rank 2
Answers by
Alex Fidanov
Telerik team
Jonx
Top achievements
Rank 2
Share this question
or