We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Upload Button in Custom Toolbar

Thread ID:

Created:

Updated:

Platform:

Replies:

132532 Sep 7,2017 02:59 AM UTC Sep 7,2017 03:11 PM UTC ASP.NET MVC 1
loading
Tags: Grid
Enrochem
Asked On September 7, 2017 02:59 AM UTC

Hi
Is there any example to render file upload control in ASP.Net MVC Grid custom tool bar.
This is to enable bulk upload of records via web page

Regards


Thavasianand Sankaranarayanan [Syncfusion]
Replied On September 7, 2017 03:11 PM UTC

Hi Enrochem, 

Thanks for contacting Syncfusion support. 

As per your request we have prepared a ASP.NET MVC Grid sample with upload box in custom toolbar and sample can be downloadable from the below location. 


Refer the below code example. 


@(Html.EJ().Grid<object>("FlatGrid") 
        .Datasource((IEnumerable<object>)ViewBag.datasource) 
        .AllowPaging() 
            .ToolbarSettings(toolbar => 
                { 
                    toolbar.ShowToolbar(true).CustomToolbarItems(new List<object>() { "Upload", new Syncfusion.JavaScript.Models.CustomToolbarItem() { TemplateID = "#UpLoad" } }); 
                }) 
                .ClientSideEvents(clientevent => clientevent.Create("create")) 
        .Columns(col => 
        { 
             
          ---- 
 
            
        })) 
 
<script id="UpLoad" type="text/x-jsrender"> 
    <div class="uploadcontrol"> 
        <div id="UploadDefault"></div> 
        </div> 
</script> 
 
<script type="text/javascript"> 
    function create(args) { 
      
        $("#UploadDefault").ejUploadbox({ 
           
            saveUrl: "/../Handler1.ashx", 
            autoUpload: true, 
            showFileDetails: false, 
            fileSize: 1048576, //bytes, 
            
        }); 
    } 
</script> 
 
--------------------------------------------- 
[Handler11.ashx] 
 
 
public void ProcessRequest(HttpContext context) 
        { 
            string targetFolder = HttpContext.Current.Server.MapPath("uploadfiles"); 
            if (!Directory.Exists(targetFolder)) 
            { 
                Directory.CreateDirectory(targetFolder); 
            } 
            HttpRequest request = context.Request; 
            HttpFileCollection uploadedFiles = context.Request.Files; 
            if (uploadedFiles != null && uploadedFiles.Count > 0) 
            { 
                for (int i = 0; i < uploadedFiles.Count; i++) 
                { 
                    if (uploadedFiles[i].FileName != null && uploadedFiles[i].FileName != "") 
                    { 
                        string fileName = uploadedFiles[i].FileName; 
                        int indx = fileName.LastIndexOf("\\"); 
                        if (indx > -1) 
                        { 
                            fileName = fileName.Substring(indx + 1); 
                        } 
                        uploadedFiles[i].SaveAs(targetFolder + "\\" + fileName); 
                    } 
                } 
            } 
        } 


For more information on rendering custom toolbar in Grid, refer the following Knowledge base documentation. 


Refer the help documentation. 



Regards, 
Thavasianand S. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;