venerdì 16 aprile 2021

Telerik RadAsyncUpload

 Un post veloce (anche per mio futuro remainder) sul componente Telerik RadAsyncUpload. Ricordarsi sempre di configurare con i giusti permessi la cartella temporanea che utilizza per l'upload dei file (quella di default è \App_Data\RadUploadTemp ), altrimenti vi darà l'errore mostrato qui sotto.



La soluzione migliore è gestire via codice il salvataggio del file sull'evento FileUploaded

protected void RadAsyncUpload1_FileUploaded(object sender, FileUploadedEventArgs e)
{
    //Get reference of the RadAsyncUpload
    RadAsyncUpload upload = (RadAsyncUpload)sender;
 
    //UniqueID
    var id = Guid.NewGuid().ToString();
 
    //Generate the Target folder according to the Test's ID
    string target = Server.MapPath("~/Tests/" + id.ToString() + "/");
 
    //Check if the generated target folder exists. If it doesn't create it.
    if(!Directory.Exists(target))
    {
        Directory.CreateDirectory(target);
    }
 
    //Get the full file name
    string fullFileName = target + e.File.FileName;
    //Save the file
    e.File.SaveAs(fullFileName);
}





Nessun commento:

Posta un commento