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

File Upload Synchronously

Thread ID:

Created:

Updated:

Platform:

Replies:

110743 Aug 22,2013 09:06 PM UTC Jan 5,2016 01:22 PM UTC JavaScript 5
loading
Tags: General
Andrew
Asked On August 22, 2013 09:06 PM UTC

I need a file upload that is able to select multple files synchronously in an html form. Is there a way to do this? It looks like your demo for the javascript controls shows it working async? I can't post to the server until the submit button of the form is selected. I'm hoping to get an example if this is possible. Thanks.

John Arokyaraj V [Syncfusion]
Replied On August 23, 2013 10:04 AM UTC

Hi Andrew,

Thanks for using Syncfusion Products.

We have provided the sample code for achieving the synchronous upload option of Uploadbox using ASP.NET MVC application.

For Synchronous Upload,

1.      We have created the submit button, reset button and the target <div> element for Uploadbox inside the Html.BeginForm.

[View Page cshtml]

 

@using (Html.BeginForm("Index", "upload", FormMethod.Post, new { id = "uploadForm", enctype = "multipart/form-data" }))

{

    <div id="syncupload"></div>

    <input type="submit" class="inputbutton" value="Upload" />

    <input type="reset" class="inputbutton" value="Reset" />

}

2.      We have initialized the ejUploadbox with asyncUpload api set to false.

 

[Script]

 

<script type="text/javascript">

    $(function () {

        $('#syncupload').ejUploadbox({ asyncUpload: false });

    });

 

</script>

 

We have provided the sample server side code for processing the form submit action.

 

[Controller c#]

 

        public ActionResult Index()

        {

            return View();

        }

        [AcceptVerbs(HttpVerbs.Post)]

        public ActionResult Index(IEnumerable<HttpPostedFileBase> syncupload)

        {

            if (syncupload != null)

                foreach (var file in syncupload)

                {

                    if (file != null)

                    {

                        var fileName = Path.GetFileName(file.FileName);

                        var destinationPath = Path.Combine(Server.MapPath("~/App_Data"), fileName);

                        file.SaveAs(destinationPath);

                        return View("UploadSuccess");

                    }

                }

            return View();

        }

 

        public ActionResult UploadSuccess()

        {

            return View();

        }

 

 

Please let us know if this helps.

 

Thanks/Regards,

John Arokyaraj.V

 


Andrew
Replied On August 23, 2013 03:39 PM UTC

Wow....perfect. Exactly what I was looking for! Thank you!

John Arokyaraj V [Syncfusion]
Replied On August 26, 2013 10:38 AM UTC

Hi Andrew,

 Thanks for your update. We appreciate the opportunity to assist you.

 Thanks/Regards,

John Arokyaraj.V


Jenson Chew
Replied On January 5, 2016 02:42 AM UTC

May I know how can I pass the file name and path value back to the .aspx.cs code behind file of the page that's implementing this client-side uploadbox control?

Arun Palaniyandi [Syncfusion]
Replied On January 5, 2016 01:22 PM UTC

Hi Jenson,

Thanks for the update.

Query:” May I know how can I pass the file name and path value back to the .aspx.cs code behind file of the page that's implementing this client-side uploadbox control?”

You can get the file details in code behind by getting the files from Request.Files and then pass into database. Please refer the below code snippet.

<code>

protected void btnUploadClick(object sender, EventArgs e)

        {

            string fname;

            HttpFileCollection hfc = Request.Files;         

                for (int i = 0; i <= hfc.Count - 1; i++)

                {

                    HttpPostedFile hpf = hfc[i];

                    if (hpf != null && hpf.ContentLength > 0)

                    {

                        fname = Path.GetFileName(hpf.FileName);

                        hpf.SaveAs(Server.MapPath(Path.Combine("~/upload/", fname)));                  

                        status.Text  += "FileName :" + fname;

                        status1.Text += "FilePath : " + Server.MapPath(Path.Combine("~/upload/"));

                        }                                                                

                }            
            }
</code>

For this scenario we have also attached a sample. Please find the sample below.
http://www.syncfusion.com/downloads/support/forum/121578/ze/upload-249855840

Please contact us in future if you have any queries.

Regards,
Arun P


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.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

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

;