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

Uplode Data To the Database

5 Answers 275 Views
Upload
This is a migrated thread and some comments may be shown as answers.
santhosh
Top achievements
Rank 1
santhosh asked on 26 Aug 2013, 07:20 AM
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

5 Answers, 1 is accepted

Sort by
0
T. Tsonev
Telerik team
answered on 26 Aug 2013, 02:30 PM
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!
0
santhosh
Top achievements
Rank 1
answered on 27 Aug 2013, 05:04 AM
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
0
T. Tsonev
Telerik team
answered on 29 Aug 2013, 11:21 AM
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!
0
santhosh
Top achievements
Rank 1
answered on 29 Aug 2013, 11:50 AM
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
0
T. Tsonev
Telerik team
answered on 30 Aug 2013, 12:52 PM
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!
Tags
Upload
Asked by
santhosh
Top achievements
Rank 1
Answers by
T. Tsonev
Telerik team
santhosh
Top achievements
Rank 1
Share this question
or