Uplode Data To the Database

6 posts, 0 answers
  1. santhosh
    santhosh avatar
    10 posts
    Member since:
    Aug 2013

    Posted 26 Aug 2013 Link to this post

    Dear all,
     i'm new to the kendo ui
    and i tried the sample of Kendo UI Uploader
    and i need to save the data to the sql server database with WCF service via Kendo Upload in Jquery
    i have the following doubts
    1) in Asynchronous mode 

    async: {
           saveUrl: "saveHandler.php",-------------------- ->> here what happens in this php file
           removeUrl: "removeHandler.php",------------------>>here what happens in this php file
           removeField: "fileNames[]"
       }
    in that saveURL you may give the savehandler.php what it happens in that PHP file 

    2) if i need to save the data in local drive then what can i do for that?????

    3) i want the original Path of the file which i had selected via kendo Uploader

    please clarify me the above issues one by one 

    thanks & regards
    -santhosh
  2. T. Tsonev
    Admin
    T. Tsonev avatar
    2772 posts

    Posted 26 Aug 2013 Link to this post

    Hi,

    As far as I'm aware WCF services allow (raw) file uploads, but does not provide any built-in support for multi-part requests. See this forum thread for details.

    The gist is that if you can make your service to accept regular form submits then it will work just fine with the Kendo UI Upload.

    As for 2) and 3) - the file will be accessible in the WCF service and can be saved at an appropriate location.
    The original file path is not available. The browsers remove it from the file name for security reasons.

    Regards,
    T. Tsonev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Kendo UI is VS 2017 Ready
  4. santhosh
    santhosh avatar
    10 posts
    Member since:
    Aug 2013

    Posted 27 Aug 2013 Link to this post

    dear T. Tsonev,

    could you please give me the sample Worked Example for the WCF service along with Kendo uploader for async mode

    and i'd worked another example
    this is my fileupload.aspx file

    $(document).ready(function ()
          {
              $("#fileuploder").kendoUpload({
                  localization: {
                      "select": "Attach"
                  },
                  async: {
                      saveUrl: "kendouploder.aspx",                   
                      autoUpload: true
                  },
                  error: function (e) {
                      alert(e);
                  }
              });
          });
    and this is my fileupload.aspx.cs Code Behind  file

    public partial class kendouploder : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
               ProcessRequest();
            }
     
         public object ProcessRequest()
            {
                     HttpFileCollection fileCollection = Request.Files;
                    for (int i = 0; i < fileCollection.Count; i++)
                    {
     
                        HttpPostedFile filePath = fileCollection[i];
                        string savepath = "D:/";
                        string filename = filePath.FileName;
                        if (!Directory.Exists(savepath))
                            Directory.CreateDirectory(savepath);
                        filePath.SaveAs(savepath + filename);
                        Response.ContentType = "application/json";
                        return "";
    }
    return "";
     }
    }
        }
    the exact problem is if i'd upload the data then it is uploaded to the path D:\  successfully  but it show error and retry button 

    could you please tell me what is the exact problem over the above example and correct it 
    i'd attached the image which shows error  but the attached file saves successfully
  5. T. Tsonev
    Admin
    T. Tsonev avatar
    2772 posts

    Posted 29 Aug 2013 Link to this post

    Hi,

    The code sample doesn't use WCF, but I can spot the problem nonetheless. The response content type is set, but there's no actual response sent.
    Please, try the following:

    public override void ProcessRequest(HttpContext context) {
        // ...

      context.Response.ContentType = "text/plain";
      context.Response.Write("");
    }

    The ProcessRequest method is void and shouldn't have a return value.

    Sample code for parsing form posts in WCF service is available in this question on SO.

    Regards,
    T. Tsonev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  6. santhosh
    santhosh avatar
    10 posts
    Member since:
    Aug 2013

    Posted 29 Aug 2013 Link to this post

    dear T. Tsonev,

    i'd used the below  code as you suggested

     public override void ProcessRequest(HttpContext context)
            {
                context.Response.Expires = -1;
                if (context.Request.Files.Count > 0)
                {
                    HttpFileCollection fileCollection = context.Request.Files;
                    if (fileCollection.Count > 0)
                    {
                        HttpPostedFile filePath = fileCollection[0];

                        string savepath = "D:/";
                        string filename = filePath.FileName;
                        if (!Directory.Exists(savepath))
                            Directory.CreateDirectory(savepath);
                        filePath.SaveAs(savepath + filename);
                        
                    }
                }
                context.Response.ContentType = "text/plain";
                        context.Response.Write("");
                
            }
    but it does not show any control binded in my HTML
     which it is shown in image

    please clarify me where i'd done the mistake
  7. T. Tsonev
    Admin
    T. Tsonev avatar
    2772 posts

    Posted 30 Aug 2013 Link to this post

    Hi,

    I guess we should terminate the request to prevent the default ASP.NET rendering from overriding our output:

    context.Response.Write("");
    context.ApplicationInstance.CompleteRequest();

    Another option would be to use a generic handler to avoid having to deal with the page life-cycle.

    Regards,
    T. Tsonev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top
Kendo UI is VS 2017 Ready