A simple upload and save file in a folder

Thread is closed for posting
4 posts, 0 answers
  1. Med
    Med avatar
    11 posts
    Member since:
    Apr 2012

    Posted 04 May 2012 Link to this post

    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
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 04 May 2012 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Med
    Med avatar
    11 posts
    Member since:
    Apr 2012

    Posted 04 May 2012 Link to this post

    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 
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 07 May 2012 Link to this post

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