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

A simple upload and save file in a folder

3 Answers 760 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Med
Top achievements
Rank 1
Med asked on 04 May 2012, 10:50 AM
Hi,
I am tring to upload a file and save it in a folder using Rad upload but it doesn't work 
I have following the same steps hier : http://www.telerik.com/help/aspnet-ajax/upload-getting-started.html 
but it doesn't explain for the button submit so i search in the forum and I found that poste : http://www.telerik.com/community/forums/aspnet/upload/is-there-an-example-about-upload-a-file-with-radupload.aspx
but it doesn't work to and it's obsolete  
 SO HOW CAN WE DO IT ?
Thankx

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 04 May 2012, 11:35 AM
Hi Med,

You can upload a file and save it into the folder using the following code snippet.

ASPX:
<telerik:RadUpload ID="RadUpload1" runat="server"></telerik:RadUpload>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" />

C#:
protected void Button1_Click(object sender, EventArgs e)
    {
        if (RadUpload1.UploadedFiles.Count > 0)
        {
            foreach (UploadedFile file in RadUpload1.UploadedFiles)
            {
                String targetFolder = Server.MapPath("~/Folder");
                file.SaveAs(Path.Combine(targetFolder, "file.txt"));
            }
        }
    }

Thanks,
Princy.
0
Med
Top achievements
Rank 1
answered on 04 May 2012, 01:52 PM
Hi Princy and that you so mutch,
It work but when i use a user control that contient the rad upload it doesn't work !!
I dont know why 
Thank you so mutch 
0
Princy
Top achievements
Rank 2
answered on 07 May 2012, 07:27 AM
Hi Med,

RadUpload cannot upload files using AJAX calls. This is a limitation of the XmlHttpRequest component, used in all AJAX frameworks for asynchronous calls to the application. In order to upload a file your application must perform a full page postback.

The solution is to attach the following function to the OnRequestStart client side event of your RadAjaxManager:

JS:
<script type="text/javascript">
    // on upload button click temporarily disables ajax to perform
    // upload actions
    function OnRequestStart(sender, args) {
        if (args.get_eventTarget() == "<%= Button1.UniqueID %>") {
            args.set_enableAjax(false);
        }
    }
</script>

Please take a look into this for more information.

Thanks,
Princy.
Tags
Upload (Obsolete)
Asked by
Med
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Med
Top achievements
Rank 1
Share this question
or