Coder Social home page Coder Social logo

devexpress-examples / gridview-how-to-upload-an-excel-file-via-uploadcontrol-and-display-its-data-in-a-grid-t449148 Goto Github PK

View Code? Open in Web Editor NEW
0.0 55.0 1.0 796 KB

Use an upload control to upload an Excel file to the server and handle the control's FileUploadComplete event to display the file's data in the grid.

License: Other

C# 2.06% JavaScript 94.38% HTML 0.72% ASP.NET 0.05% Visual Basic .NET 2.79%
dotnet mvc-gridview asp-net-mvc excel upload

gridview-how-to-upload-an-excel-file-via-uploadcontrol-and-display-its-data-in-a-grid-t449148's Introduction

Grid View for ASP.NET MVC - How to upload an Excel file using an upload control and display the file's data in the grid

This example demonstrates how to use an upload control to upload an Excel file to the server and handle the control's FileUploadComplete event to display the file's data in the grid.

Overview

Create an upload control, specify its CallbackRouteValues action, and call the GetUploadedFiles method to upload an Excel file. Save the file's path and use the e.CallbackData argument property to pass the path to the client.

public class HomeController : Controller {
    public ActionResult UploadControlUpload() {
        UploadControlExtension.GetUploadedFiles("UploadControlFile", UploadControlSettings.UploadValidationSettings, UploadControlSettings.FileUploadComplete);
        return null;
    }
}
public class UploadControlSettings {
    public static DevExpress.Web.UploadControlValidationSettings UploadValidationSettings = new DevExpress.Web.UploadControlValidationSettings() {
        AllowedFileExtensions = new string[] {".xlsx" },
        MaxFileSize = 40000000
    };
    public static void FileUploadComplete(object sender, DevExpress.Web.FileUploadCompleteEventArgs e) {
        const string UploadDirectory = "~/Content/UploadedFiles/";
        if (e.UploadedFile.IsValid) {
            MemoryStream ms = new MemoryStream();
            // ...
            e.UploadedFile.SaveAs(resultFilePath);
            e.CallbackData = resultFilePath;
        }
    }
}

Handle the upload control's FileUploadColmplete event. In the handler, call the grid's PerformCallback method to send a callback to the server and pass the file's path as a parameter.

settings.ClientSideEvents.FileUploadComplete = "function(s, e) { GridView1.PerformCallback({ path: e.callbackData}); }";

To display the file's data in the grid, use the approach illustrated in the following example: Grid View for ASP.NET MVC - How to bind the grid to an excel file.

Files to Review

More Examples

gridview-how-to-upload-an-excel-file-via-uploadcontrol-and-display-its-data-in-a-grid-t449148's People

Contributors

devexpressexamplebot avatar elenapeskova avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

elenapeskova

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.