Start upload without FileOpen Dialog

3 posts, 1 answers
  1. Sami
    Sami avatar
    12 posts
    Member since:
    Feb 2011

    Posted 02 Dec 2013 Link to this post

    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. Egemen
    Egemen avatar
    34 posts
    Member since:
    Apr 2012

    Posted 05 Dec 2013 Link to this post

    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

  3. DevCraft banner
  4. Answer
    Kiril Vandov
    Admin
    Kiril Vandov avatar
    324 posts

    Posted 05 Dec 2013 Link to this post

    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 >>
Back to Top