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

KeyNotFoundException when setting e.NewFileStream

1 Answer 50 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Tyler
Top achievements
Rank 1
Tyler asked on 20 Oct 2011, 07:31 PM
I'm creating a RadUpload control in code when I try to change the stream for the file being uploaded I get the following exception.  The stream gets uploaded but seems to be missing part of the contents.   The initial file that is being added to ValidFiles is just there as a placeholder so that the FileUploadStarting event will fire.

The given key was not present in the dictionary.

   at System.ThrowHelper.ThrowKeyNotFoundException()
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at Telerik.Windows.Controls.RadUpload.OnFileUploadSizeChanged(Object sender, EventArgs e)


RadUpload upload = new RadUpload();
            upload.TargetFolder = "UserUploads";
            upload.OverwriteExistingFiles = true;
            upload.UploadServiceUrl = "../FileUploadHandler.ashx";
            upload.CurrentSession.ValidFiles.Add(file.Name, new RadUploadSelectedFile(file));
 
            upload.FileUploadStarting += new System.EventHandler<FileUploadStartingEventArgs>(upload_FileUploadStarting); 
            upload.UploadFinished += new RoutedEventHandler(upload_UploadFinished);
 
            upload.StartUpload();
void upload_FileUploadStarting(object sender, FileUploadStartingEventArgs e)
{
    e.NewFileStream = GetCsvStream();
}

1 Answer, 1 is accepted

Sort by
0
Tyler
Top achievements
Rank 1
answered on 21 Oct 2011, 10:04 PM
Found the answer had to use SelectedFiles instead of ValidFiles and call PrepareSelectedFilesForUpload()
upload.CurrentSession.SelectedFiles.Add(new RadUploadSelectedFile(file));             
upload.PrepareSelectedFilesForUpload();

Tags
Upload
Asked by
Tyler
Top achievements
Rank 1
Answers by
Tyler
Top achievements
Rank 1
Share this question
or