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

Start upload without FileOpen Dialog

2 Answers 25 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Sami
Top achievements
Rank 1
Sami asked on 03 Dec 2013, 12:58 AM
Hi, I have a problem with the RadUpload control. I need to upload a stream (byte array) to the server as a file, in the event FileUploadStarting I can set the stream in the NewFileStream property of the EventArgs parameter, and the stream is uploaded fine, but the problem is the RadUpload needs to open the FileDialog to select the files to upload, if I don't do that, the StartUpload method doesn't work. Is there any way to force upload without open FileDialog?

Thanks in advanced...
Sami

2 Answers, 1 is accepted

Sort by
0
Egemen
Top achievements
Rank 1
answered on 05 Dec 2013, 09:40 AM
Hi,

You have to create an radupload programmatic like this.
RadUpload radUploadControl = new RadUpload();
//Configure
 radUploadControl.UploadServiceUrl = "/ImageUploader.ashx";
 radUploadControl.TargetFolder = "ImageStorageFolder";

 radUploadControl.BufferSize = 100000;
 radUploadControl.Filter = "Image Files (*.gif;*.jpg;*.jpeg;*.png)|*.gif;*.jpg;*.jpeg;*.png";
 radUploadControl.FilterIndex = 3;
 radUploadControl.IsAutomaticUpload = true;

//and add the files
FileInfo fi = new FileInfo(".....");
 RadUploadSelectedFile f = new RadUploadSelectedFile(fi);          
radUploadControl.CurrentSession.SelectedFiles.Add(f); 

//Start upload
 radUploadControl.PrepareSelectedFilesForUpload();
 radUploadControl.StartUpload();

Regards

0
Accepted
Kiril Vandov
Telerik team
answered on 05 Dec 2013, 03:16 PM
Hello Sami,

You can upload files without using the OpenFileDialog. In order to do that you need to do the following steps on buttons click for instance:
//Open the file in a stream
FileStream stream = new FileStream(@"C:\Users\vandov\Documents\My Received Files\broken.png", FileMode.Open);
// Create a new RadUploadSelecteFile   
RadUploadSelectedFile file = new RadUploadSelectedFile(stream, "broken.png");
// Add the file to the current sesion      
this.RadUpload.CurrentSession.SelectedFiles.Add(file);
// Force the control to prepare the selected items(it is some kind of a validation)
this.RadUpload.PrepareSelectedFilesForUpload();
// Start the Upload
this.RadUpload.StartUpload();

I hope this information helps.

Kind regards,
Kiril Vandov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
Upload
Asked by
Sami
Top achievements
Rank 1
Answers by
Egemen
Top achievements
Rank 1
Kiril Vandov
Telerik team
Share this question
or