Sample .NET Webservice for Async

10 posts, 0 answers
  1. Jeremy
    Jeremy avatar
    55 posts
    Member since:
    Nov 2011

    Posted 28 Jun 2012 Link to this post

    Does anyone have a sample for writing the Async handlers for the upload control using webservices in .net?

    I'll be your best friend.



  2. Majid
    Majid avatar
    5 posts
    Member since:
    Jan 2012

    Posted 25 Sep 2012 Link to this post

    looking for the same. 
    plz help
  3. Kendo UI is VS 2017 Ready
  4. Ty Kang
    Ty Kang avatar
    1 posts
    Member since:
    Nov 2006

    Posted 26 Sep 2012 Link to this post

    I have a pretty full example. I can supply a little later today.
  5. Majid
    Majid avatar
    5 posts
    Member since:
    Jan 2012

    Posted 26 Sep 2012 Link to this post

    Waiting for you :)
  6. Jeremy
    Jeremy avatar
    55 posts
    Member since:
    Nov 2011

    Posted 26 Sep 2012 Link to this post

    Here you go.  (I work with Ty Kang) 

    Attached are the core of the files I use. It does the following:

    Renders a Kendo grid of attachments, and wires up an upload control.
    The Upload control communicates with a .NET handler.
    On upload data is passed to the handler from javascript
    The handler received the data, parses it, saves the files.
    Error and Success events are then handled.

    You'll have to modify the code, as it contains some of my specific actions that you will need, but I left some extra stuff in, in case it helps.

  7. Majid
    Majid avatar
    5 posts
    Member since:
    Jan 2012

    Posted 26 Sep 2012 Link to this post

    Thanks Jeremy for helping me out.
    I actually was trying to upload files via a RESTful WCF service.
    But now i have created a handler in my project to save the uploaded files. 
    And now although files are being uploaded sucessfully to the server, but a problem is there, Kendo upload control is showing that file is not uploaded and a retry button is showing on the control.
  8. Majid
    Majid avatar
    5 posts
    Member since:
    Jan 2012

    Posted 26 Sep 2012 Link to this post

    I have made it.   :)
    I had to send httpStatusCode "OK" in response.

    Once again thanks for helping.
  9. Jeremy
    Jeremy avatar
    55 posts
    Member since:
    Nov 2011

    Posted 27 Sep 2012 Link to this post

    I am actually having the same issue of the control not properly knowing if it is fail or success.  

    What do you mean by  httpStatusCode "OK" ?

    How about for my benefit and other who will find this thread later, can you post your sample handle as well?


  10. Majid
    Majid avatar
    5 posts
    Member since:
    Jan 2012

    Posted 27 Sep 2012 Link to this post

    Sure! Why not
    So here it goes...

    My handlerFile looks like this :

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.IO;
    using System.Net;


    namespace WebApplicationCE.Admin
    {
        /// <summary>
        /// Summary description for FileHandler
        /// </summary>
        public class FileHandler : IHttpHandler
        {


            public void ProcessRequest(HttpContext context)
            {
                try
                {
                    if (!string.IsNullOrEmpty(context.Request.QueryString["upload"]))
                    {
                        HttpPostedFile postedFile = context.Request.Files["files"];
                        string filepath = context.Server.MapPath("AdminFiles");
                        string filename = postedFile.FileName;
                        if (!Directory.Exists(filepath))
                            Directory.CreateDirectory(filepath);
                        postedFile.SaveAs(Path.Combine(filepath, filename));
                        context.Response.StatusCode = (int)HttpStatusCode.OK;
                    }
                    else if (!string.IsNullOrEmpty(context.Request.QueryString["remove"]))
                    {
                        string filepath = context.Server.MapPath("AdminFiles");
                        string filename = context.Request.Form["fileNames"];
                        FileInfo file = new FileInfo(Path.Combine(filepath, filename));
                        file.Delete();
                        context.Response.StatusCode = (int)HttpStatusCode.OK;
                    }
                   
                }
                catch (Exception ex)
                {
                     context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                }
            }


            public bool IsReusable
            {
                get
                {
                    return false;
                }
            }
        }
    }

    And here is the calling code :

    <input name="files" id="files" type="file"/>
    <script type="text/javascript">
        $('files').kendoUpload({
                                async: {
                                    saveUrl: "FileHandler.ashx?upload=true",
                                    removeUrl: "FileHandler.ashx?remove=true",
                                    autoUpload: true
                                },
                                success: fileUploadSuccess,
                                error: fileUploadError
                            });
                        }
                        function fileUploadSuccess(result) {
                           alert(result.XMLHttpRequest.statusText);
                        }
                        function fileUploadError(result) {
                          alert(result.XMLHttpRequest.statusText);
                        }

    </script>
  11. Gerry
    Gerry avatar
    7 posts
    Member since:
    Sep 2012

    Posted 23 Dec 2014 in reply to Majid Link to this post

    I guess this question is not worth their time to answer.  I hope that I have understood the problem.

    *** JS code
    $("#upload").kendoUpload({
            multiple: false,
            async: {
                saveUrl: "/DataService/Upload.ashx",
                autoUpload: false
            },
            template: kendo.template($('#fileTemplate').html()),
        }).closest(".k-upload").find("span").text("Select One Bulk Load Excel Spread Sheet...");  

    **** c# => NOTE that I store this handler in a DataService folder
    public class Upload : IHttpHandler
        {
            public void ProcessRequest(HttpContext context)
            {
                context.Response.Expires = -1;
                try
                {
                    HttpPostedFile postedFile = context.Request.Files["upload"];
                    //do something with your postedfile
                    context.Response.ContentType = "application/json";
                    context.Response.Write("{}");
                }
                catch (Exception ex)
                {
                    context.Response.Write(ex.ToString());

                }
            }

            public bool IsReusable
            {
                get
                {
                    return false;
                }
            }
        }



Back to Top
Kendo UI is VS 2017 Ready