0

First of all I am new to Kendo Uploder. I have a kendo Uploader in my page . I don't know what I am doing wrong as it didn't hit my VB Method.

Markup :

    <script id="fileTemplate" type="text/x-kendo-template">
                <span class='k-progress'></span>
                <div class='file-wrapper'>
                    <h4 class='file-heading file-name-heading'>Name: #=name#</h4>
                    <h4 class='file-heading file-size-heading'>Size: #=size# bytes</h4>
                    <button type='button' class='k-upload-action'></button>
                </div>
    </script>

    <script>
        $(document).ready(function () {
            $("#files").kendoUpload({
                multiple: true,
                async: {
                    saveUrl: "NewFolder.aspx/UploadSubSRFiles",
                    removeUrl: "Remove",
                    autoUpload: true
                },
                upload: onUpload,
                template: kendo.template($('#fileTemplate').html())
            });
            function onUpload(e) {

                var paramsEmailDocs = "{'strFiles':'" + e.files + "'}"
                Request.files
                $.ajax({
                    type: "POST",
                    url: "NewFolder.aspx/UploadSubSRFiles",
                    data: paramsEmailDocs ,
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    async: false,
                    success: function (data) {

                    }
                })
            }
        });
    </script>

HTML:

<div id="example" class="k-content">
     <input type="file" name="files" id="files" />
</div>

VB Method:

    ''' <summary>
    ''' Method for getting the Template Service request Object
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    <WebMethod()> _
    Public Shared Function UploadSubSRFiles(ByVal strFiles As HttpPostedFileBase) As Boolean
        Try
            If lngUserID > 0 Then
                Return True
            Else
                Return Nothing
            End If
        Catch ex As Exception
            Debug.WriteLine("Error in UploadSubSRFiles method of Folder page: " + ex.Message)
            Return Nothing
        End Try
    End Function

Problem: In the front end when I drag the files . Files description comes properly according to the template. But the VB method never gets hit. I am quite new to this so may be my VB or script code is wrong . Kindly guide me.

Any Help will be highly appreciated.

Nitin Rawat
  • 209
  • 1
  • 5
  • 14

2 Answers2

1

You cannot pass parameters to methods that handle file uploading using .aspx or .asmx methods. What you must do is create an upload handler.

JS Code:

  $("#files").kendoUpload({
            multiple: false,
            async: {
                saveUrl: '/UploadHandler.ashx'
            },
            upload: function (request) {
                // custom parameters
                request.data = { companyId: _companyId };
            }
        });

C# (VB)

<%@ WebHandler Language="C#" Class="UploadHandler" %>

using System;
using System.Web;

public class UploadHandler : IHttpHandler {

    public void ProcessRequest (HttpContext context)
    {
        var file = context.Request.Files[0];
        var companyId = context.Request.Form["companyId"];
        context.Response.ContentType = "text/plain";
        context.Response.Write("Hello World");
    }

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

If you don't need to pass custom parameters just get files from Context.Request.Files from .asmx, .aspx page web method.

IHAFURR
  • 111
  • 4
0

You can't upload files with $.ajax. Basically you don't need to set the upload event handler. Just setting async.saveUrl should be enough. Here is a live demo http://demos.telerik.com/kendo-ui/web/upload/async.html

Atanas Korchev
  • 30,562
  • 8
  • 59
  • 93
  • Yes I tried that also after removing the upload but my VB method is not hitting at all. My question is that what I am missing in my VB method. – Nitin Rawat Apr 08 '14 at 09:09
  • The demo you pointed uses a URL "save" , In my case I have a method in VB file which will contain the code to save the data to the DB. I don't know what I am missing as it is not getting hit. – Nitin Rawat Apr 08 '14 at 09:11
  • Check your browser developer tools for any HTTP errors. – Atanas Korchev Apr 08 '14 at 10:33