export file with asp.netHow do I create an Excel (.XLS and .XLSX) file in C# without installing Microsoft Office?What Datatype to use for this so that the image can upload to the SQL Server?File Upload ASP.NET MVC 3.0How to format numbers as string data-types while exporting to Excel in ASP.NET?Programmatically getting the total no. of rows having data in excel sheet using C#is there is a way to direct convert dbgeometry or sqlgeometry to shape file?EPPLUS cannot delete worksheet >> “Part does not exist” (System.InvalidOperationException)Export data from Excel to AzureHow to import and export excel in angular and asp.net core projectEPPlus - ExcelPackage loading multiple sheets from a Stream/FileInfo generates an excel document with no data

To which airspace does the border of two adjacent airspaces belong to?

Does POSIX guarantee the paths to any standard utilities?

Why do old games use flashing as means of showing damage?

Do I need to get a noble in order to win Splendor?

How to find better food in airports

What is this red bug infesting some trees in southern Germany?

Go for an isolated pawn

What is the significance of 104% for throttle power and rotor speed?

How do you manage to study and have a balance in your life at the same time?

Main differences between 5th edition Druid and 3.5 edition Druid

How to encode a class with 24,000 categories?

std::tuple sizeof, is it a missed optimization?

Does this bike use hydraulic brakes?

pruning subdomains of other domains in a file using script (bash, awk or similar)

Travel to USA with a stuffed puppet

What is the difference between "wie" and "nach" in "Klingt wie/nach..."

Splitting polygons at narrowest part using R?

Why don't they build airplanes from 3D printer plastic?

Question about derivation of kinematics equations

What happens when there is no available physical memory left for SQL Server?

How will the UK Commons debate tonight despite the prorogation?

Adding transparency to ink drawing

How could it be that the capo isn't changing the pitch?

How does Harry wear the invisibility cloak?



export file with asp.net


How do I create an Excel (.XLS and .XLSX) file in C# without installing Microsoft Office?What Datatype to use for this so that the image can upload to the SQL Server?File Upload ASP.NET MVC 3.0How to format numbers as string data-types while exporting to Excel in ASP.NET?Programmatically getting the total no. of rows having data in excel sheet using C#is there is a way to direct convert dbgeometry or sqlgeometry to shape file?EPPLUS cannot delete worksheet >> “Part does not exist” (System.InvalidOperationException)Export data from Excel to AzureHow to import and export excel in angular and asp.net core projectEPPlus - ExcelPackage loading multiple sheets from a Stream/FileInfo generates an excel document with no data






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















This project is an ASP.Net Api project with Angular. What I'm trying to do is export data from a database table and into an excel file. So far, I've managed to export all the table data into an excel file, but struggle to select 2 or 3 fields in the table to export.



 [HttpGet("download")]
public IActionResult DownloadExcel(string field)

string dbFileName = "DbTableName.xlsx";


FileInfo file = new FileInfo(dbFileName);
byte[] fileContents;

var stream = new MemoryStream();
using (ExcelPackage package = new ExcelPackage(file))


IList<UserTable> userList = _context.UserTable.ToList();

ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("DbTableName");
int totalUserRows = userList.Count();





return File(fileContents, fileType, dbFileName);










share|improve this question
































    1















    This project is an ASP.Net Api project with Angular. What I'm trying to do is export data from a database table and into an excel file. So far, I've managed to export all the table data into an excel file, but struggle to select 2 or 3 fields in the table to export.



     [HttpGet("download")]
    public IActionResult DownloadExcel(string field)

    string dbFileName = "DbTableName.xlsx";


    FileInfo file = new FileInfo(dbFileName);
    byte[] fileContents;

    var stream = new MemoryStream();
    using (ExcelPackage package = new ExcelPackage(file))


    IList<UserTable> userList = _context.UserTable.ToList();

    ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("DbTableName");
    int totalUserRows = userList.Count();





    return File(fileContents, fileType, dbFileName);










    share|improve this question




























      1












      1








      1








      This project is an ASP.Net Api project with Angular. What I'm trying to do is export data from a database table and into an excel file. So far, I've managed to export all the table data into an excel file, but struggle to select 2 or 3 fields in the table to export.



       [HttpGet("download")]
      public IActionResult DownloadExcel(string field)

      string dbFileName = "DbTableName.xlsx";


      FileInfo file = new FileInfo(dbFileName);
      byte[] fileContents;

      var stream = new MemoryStream();
      using (ExcelPackage package = new ExcelPackage(file))


      IList<UserTable> userList = _context.UserTable.ToList();

      ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("DbTableName");
      int totalUserRows = userList.Count();





      return File(fileContents, fileType, dbFileName);










      share|improve this question
















      This project is an ASP.Net Api project with Angular. What I'm trying to do is export data from a database table and into an excel file. So far, I've managed to export all the table data into an excel file, but struggle to select 2 or 3 fields in the table to export.



       [HttpGet("download")]
      public IActionResult DownloadExcel(string field)

      string dbFileName = "DbTableName.xlsx";


      FileInfo file = new FileInfo(dbFileName);
      byte[] fileContents;

      var stream = new MemoryStream();
      using (ExcelPackage package = new ExcelPackage(file))


      IList<UserTable> userList = _context.UserTable.ToList();

      ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("DbTableName");
      int totalUserRows = userList.Count();





      return File(fileContents, fileType, dbFileName);







      c# asp.net-core






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 29 at 21:08







      Jenny From the Block

















      asked Mar 28 at 2:34









      Jenny From the BlockJenny From the Block

      487 bronze badges




      487 bronze badges

























          2 Answers
          2






          active

          oldest

          votes


















          0
















          There's no need to write so many if ... else if ... else if ... else if ... to get the related field names.



          A nicer way is to



          1. Use a field list (IList<string>)as a parameter.

          2. And then generate a required field list by intersect.

          3. Finally, we could use reflection to retrieve all the related values.

          Implementation



           public IActionResult DownloadExcel(IList<string> fields)

          // get the required field list
          var userType = typeof(UserTable);
          fields = userType.GetProperties().Select(p => p.Name).Intersect(fields).ToList();

          if(fields.Count == 0) return BadRequest();

          using (ExcelPackage package = new ExcelPackage())

          IList<UserTable> userList = _context.UserTable.ToList();
          ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("DbTableName");

          // generate header line
          for(var i= 0; i< fields.Count; i++ )
          var fieldName = fields[i];
          var pi= userType.GetProperty(fieldName);
          var displayName = pi.GetCustomAttribute<DisplayNameAttribute>()?.DisplayName;
          worksheet.Cells[1,i+1].Value = string.IsNullOrEmpty(displayName ) ? fieldName : displayName ;


          // generate row lines
          int totalUserRows = userList.Count();
          for(var r=0; r< userList.Count(); r++)
          var row = userList[r];
          for(var c=0 ; c< fields.Count;c++)
          var fieldName = fields[c];
          var pi = userType.GetProperty(fieldName);
          // because the first row is header
          worksheet.Cells[r+2, c+1].Value = pi.GetValue(row);


          var stream = new MemoryStream(package.GetAsByteArray());
          return new FileStreamResult(stream,"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");




          You could configure the display name using the DsiplayNameAttribute:



           public class UserTable

          public int Idget;set;

          [DisplayName("First Name")]
          public string fName get; set;

          [DisplayName("Last Name")]
          public string lName get; set;

          [DisplayName("Gender")]
          public string gender get; set;




          It's possible to add any properties as you like without hard-coding in your DownloadExcel method.



          Demo :



          passing a field list fields[0]=fName&fields[1]=lName&fields[2]=Non-Exist will generate an excel as below:



          enter image description here



          [Update]



          To export all the fields, we could assume the client will not pass a fields parameter. That means when the fields is null or if the fields.Count==0, we'll export all the fields:



           [HttpGet("download")]
          public IActionResult DownloadExcel(IList<string> fields)

          // get the required field list
          var userType = typeof(UserTable);
          var pis= userType.GetProperties().Select(p => p.Name);

          if(fields?.Count >0)
          fields = pis.Intersect(fields).ToList();
          else
          fields = pis.ToList();


          using (ExcelPackage package = new ExcelPackage())
          ....




          A






          share|improve this answer



























          • Oh my God @itminus! It worked so well!. Thank you so much for the assistance.

            – Jenny From the Block
            Mar 29 at 1:14











          • If I were wanting to export all the data from the table, can't I do something like fields=null? or fields=all?

            – Jenny From the Block
            Mar 29 at 1:15











          • @JennyFromtheBlock I've updated my answer. If the client doesn't specify a parameter of fields ( that means fields==null or fields.Count==0), we will export all the fields.

            – itminus
            Mar 29 at 1:37












          • I can't thank you enough! I have learned a lot! I hope this helps others as well!

            – Jenny From the Block
            Mar 29 at 2:03


















          0
















          if you want to use the datatable then we can define which you need to select from the datatable in this way



          string[] selectedColumns = new[] "Column1","Column2";
          DataTable dt= new DataView(fromDataTable).ToTable(false, selectedColumns);


          or else if you wanna you list then you can use linq for selection of particular columns



          var xyz = from a in prod.Categories
          where a.CatName.EndsWith("A")
          select new CatName=a.CatName, CatID=a.CatID, CatQty = a.CatQty;





          share|improve this answer



























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55389349%2fexport-file-with-asp-net%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0
















            There's no need to write so many if ... else if ... else if ... else if ... to get the related field names.



            A nicer way is to



            1. Use a field list (IList<string>)as a parameter.

            2. And then generate a required field list by intersect.

            3. Finally, we could use reflection to retrieve all the related values.

            Implementation



             public IActionResult DownloadExcel(IList<string> fields)

            // get the required field list
            var userType = typeof(UserTable);
            fields = userType.GetProperties().Select(p => p.Name).Intersect(fields).ToList();

            if(fields.Count == 0) return BadRequest();

            using (ExcelPackage package = new ExcelPackage())

            IList<UserTable> userList = _context.UserTable.ToList();
            ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("DbTableName");

            // generate header line
            for(var i= 0; i< fields.Count; i++ )
            var fieldName = fields[i];
            var pi= userType.GetProperty(fieldName);
            var displayName = pi.GetCustomAttribute<DisplayNameAttribute>()?.DisplayName;
            worksheet.Cells[1,i+1].Value = string.IsNullOrEmpty(displayName ) ? fieldName : displayName ;


            // generate row lines
            int totalUserRows = userList.Count();
            for(var r=0; r< userList.Count(); r++)
            var row = userList[r];
            for(var c=0 ; c< fields.Count;c++)
            var fieldName = fields[c];
            var pi = userType.GetProperty(fieldName);
            // because the first row is header
            worksheet.Cells[r+2, c+1].Value = pi.GetValue(row);


            var stream = new MemoryStream(package.GetAsByteArray());
            return new FileStreamResult(stream,"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");




            You could configure the display name using the DsiplayNameAttribute:



             public class UserTable

            public int Idget;set;

            [DisplayName("First Name")]
            public string fName get; set;

            [DisplayName("Last Name")]
            public string lName get; set;

            [DisplayName("Gender")]
            public string gender get; set;




            It's possible to add any properties as you like without hard-coding in your DownloadExcel method.



            Demo :



            passing a field list fields[0]=fName&fields[1]=lName&fields[2]=Non-Exist will generate an excel as below:



            enter image description here



            [Update]



            To export all the fields, we could assume the client will not pass a fields parameter. That means when the fields is null or if the fields.Count==0, we'll export all the fields:



             [HttpGet("download")]
            public IActionResult DownloadExcel(IList<string> fields)

            // get the required field list
            var userType = typeof(UserTable);
            var pis= userType.GetProperties().Select(p => p.Name);

            if(fields?.Count >0)
            fields = pis.Intersect(fields).ToList();
            else
            fields = pis.ToList();


            using (ExcelPackage package = new ExcelPackage())
            ....




            A






            share|improve this answer



























            • Oh my God @itminus! It worked so well!. Thank you so much for the assistance.

              – Jenny From the Block
              Mar 29 at 1:14











            • If I were wanting to export all the data from the table, can't I do something like fields=null? or fields=all?

              – Jenny From the Block
              Mar 29 at 1:15











            • @JennyFromtheBlock I've updated my answer. If the client doesn't specify a parameter of fields ( that means fields==null or fields.Count==0), we will export all the fields.

              – itminus
              Mar 29 at 1:37












            • I can't thank you enough! I have learned a lot! I hope this helps others as well!

              – Jenny From the Block
              Mar 29 at 2:03















            0
















            There's no need to write so many if ... else if ... else if ... else if ... to get the related field names.



            A nicer way is to



            1. Use a field list (IList<string>)as a parameter.

            2. And then generate a required field list by intersect.

            3. Finally, we could use reflection to retrieve all the related values.

            Implementation



             public IActionResult DownloadExcel(IList<string> fields)

            // get the required field list
            var userType = typeof(UserTable);
            fields = userType.GetProperties().Select(p => p.Name).Intersect(fields).ToList();

            if(fields.Count == 0) return BadRequest();

            using (ExcelPackage package = new ExcelPackage())

            IList<UserTable> userList = _context.UserTable.ToList();
            ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("DbTableName");

            // generate header line
            for(var i= 0; i< fields.Count; i++ )
            var fieldName = fields[i];
            var pi= userType.GetProperty(fieldName);
            var displayName = pi.GetCustomAttribute<DisplayNameAttribute>()?.DisplayName;
            worksheet.Cells[1,i+1].Value = string.IsNullOrEmpty(displayName ) ? fieldName : displayName ;


            // generate row lines
            int totalUserRows = userList.Count();
            for(var r=0; r< userList.Count(); r++)
            var row = userList[r];
            for(var c=0 ; c< fields.Count;c++)
            var fieldName = fields[c];
            var pi = userType.GetProperty(fieldName);
            // because the first row is header
            worksheet.Cells[r+2, c+1].Value = pi.GetValue(row);


            var stream = new MemoryStream(package.GetAsByteArray());
            return new FileStreamResult(stream,"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");




            You could configure the display name using the DsiplayNameAttribute:



             public class UserTable

            public int Idget;set;

            [DisplayName("First Name")]
            public string fName get; set;

            [DisplayName("Last Name")]
            public string lName get; set;

            [DisplayName("Gender")]
            public string gender get; set;




            It's possible to add any properties as you like without hard-coding in your DownloadExcel method.



            Demo :



            passing a field list fields[0]=fName&fields[1]=lName&fields[2]=Non-Exist will generate an excel as below:



            enter image description here



            [Update]



            To export all the fields, we could assume the client will not pass a fields parameter. That means when the fields is null or if the fields.Count==0, we'll export all the fields:



             [HttpGet("download")]
            public IActionResult DownloadExcel(IList<string> fields)

            // get the required field list
            var userType = typeof(UserTable);
            var pis= userType.GetProperties().Select(p => p.Name);

            if(fields?.Count >0)
            fields = pis.Intersect(fields).ToList();
            else
            fields = pis.ToList();


            using (ExcelPackage package = new ExcelPackage())
            ....




            A






            share|improve this answer



























            • Oh my God @itminus! It worked so well!. Thank you so much for the assistance.

              – Jenny From the Block
              Mar 29 at 1:14











            • If I were wanting to export all the data from the table, can't I do something like fields=null? or fields=all?

              – Jenny From the Block
              Mar 29 at 1:15











            • @JennyFromtheBlock I've updated my answer. If the client doesn't specify a parameter of fields ( that means fields==null or fields.Count==0), we will export all the fields.

              – itminus
              Mar 29 at 1:37












            • I can't thank you enough! I have learned a lot! I hope this helps others as well!

              – Jenny From the Block
              Mar 29 at 2:03













            0














            0










            0









            There's no need to write so many if ... else if ... else if ... else if ... to get the related field names.



            A nicer way is to



            1. Use a field list (IList<string>)as a parameter.

            2. And then generate a required field list by intersect.

            3. Finally, we could use reflection to retrieve all the related values.

            Implementation



             public IActionResult DownloadExcel(IList<string> fields)

            // get the required field list
            var userType = typeof(UserTable);
            fields = userType.GetProperties().Select(p => p.Name).Intersect(fields).ToList();

            if(fields.Count == 0) return BadRequest();

            using (ExcelPackage package = new ExcelPackage())

            IList<UserTable> userList = _context.UserTable.ToList();
            ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("DbTableName");

            // generate header line
            for(var i= 0; i< fields.Count; i++ )
            var fieldName = fields[i];
            var pi= userType.GetProperty(fieldName);
            var displayName = pi.GetCustomAttribute<DisplayNameAttribute>()?.DisplayName;
            worksheet.Cells[1,i+1].Value = string.IsNullOrEmpty(displayName ) ? fieldName : displayName ;


            // generate row lines
            int totalUserRows = userList.Count();
            for(var r=0; r< userList.Count(); r++)
            var row = userList[r];
            for(var c=0 ; c< fields.Count;c++)
            var fieldName = fields[c];
            var pi = userType.GetProperty(fieldName);
            // because the first row is header
            worksheet.Cells[r+2, c+1].Value = pi.GetValue(row);


            var stream = new MemoryStream(package.GetAsByteArray());
            return new FileStreamResult(stream,"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");




            You could configure the display name using the DsiplayNameAttribute:



             public class UserTable

            public int Idget;set;

            [DisplayName("First Name")]
            public string fName get; set;

            [DisplayName("Last Name")]
            public string lName get; set;

            [DisplayName("Gender")]
            public string gender get; set;




            It's possible to add any properties as you like without hard-coding in your DownloadExcel method.



            Demo :



            passing a field list fields[0]=fName&fields[1]=lName&fields[2]=Non-Exist will generate an excel as below:



            enter image description here



            [Update]



            To export all the fields, we could assume the client will not pass a fields parameter. That means when the fields is null or if the fields.Count==0, we'll export all the fields:



             [HttpGet("download")]
            public IActionResult DownloadExcel(IList<string> fields)

            // get the required field list
            var userType = typeof(UserTable);
            var pis= userType.GetProperties().Select(p => p.Name);

            if(fields?.Count >0)
            fields = pis.Intersect(fields).ToList();
            else
            fields = pis.ToList();


            using (ExcelPackage package = new ExcelPackage())
            ....




            A






            share|improve this answer















            There's no need to write so many if ... else if ... else if ... else if ... to get the related field names.



            A nicer way is to



            1. Use a field list (IList<string>)as a parameter.

            2. And then generate a required field list by intersect.

            3. Finally, we could use reflection to retrieve all the related values.

            Implementation



             public IActionResult DownloadExcel(IList<string> fields)

            // get the required field list
            var userType = typeof(UserTable);
            fields = userType.GetProperties().Select(p => p.Name).Intersect(fields).ToList();

            if(fields.Count == 0) return BadRequest();

            using (ExcelPackage package = new ExcelPackage())

            IList<UserTable> userList = _context.UserTable.ToList();
            ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("DbTableName");

            // generate header line
            for(var i= 0; i< fields.Count; i++ )
            var fieldName = fields[i];
            var pi= userType.GetProperty(fieldName);
            var displayName = pi.GetCustomAttribute<DisplayNameAttribute>()?.DisplayName;
            worksheet.Cells[1,i+1].Value = string.IsNullOrEmpty(displayName ) ? fieldName : displayName ;


            // generate row lines
            int totalUserRows = userList.Count();
            for(var r=0; r< userList.Count(); r++)
            var row = userList[r];
            for(var c=0 ; c< fields.Count;c++)
            var fieldName = fields[c];
            var pi = userType.GetProperty(fieldName);
            // because the first row is header
            worksheet.Cells[r+2, c+1].Value = pi.GetValue(row);


            var stream = new MemoryStream(package.GetAsByteArray());
            return new FileStreamResult(stream,"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");




            You could configure the display name using the DsiplayNameAttribute:



             public class UserTable

            public int Idget;set;

            [DisplayName("First Name")]
            public string fName get; set;

            [DisplayName("Last Name")]
            public string lName get; set;

            [DisplayName("Gender")]
            public string gender get; set;




            It's possible to add any properties as you like without hard-coding in your DownloadExcel method.



            Demo :



            passing a field list fields[0]=fName&fields[1]=lName&fields[2]=Non-Exist will generate an excel as below:



            enter image description here



            [Update]



            To export all the fields, we could assume the client will not pass a fields parameter. That means when the fields is null or if the fields.Count==0, we'll export all the fields:



             [HttpGet("download")]
            public IActionResult DownloadExcel(IList<string> fields)

            // get the required field list
            var userType = typeof(UserTable);
            var pis= userType.GetProperties().Select(p => p.Name);

            if(fields?.Count >0)
            fields = pis.Intersect(fields).ToList();
            else
            fields = pis.ToList();


            using (ExcelPackage package = new ExcelPackage())
            ....




            A







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 29 at 1:35

























            answered Mar 28 at 6:47









            itminusitminus

            7,0361 gold badge5 silver badges24 bronze badges




            7,0361 gold badge5 silver badges24 bronze badges















            • Oh my God @itminus! It worked so well!. Thank you so much for the assistance.

              – Jenny From the Block
              Mar 29 at 1:14











            • If I were wanting to export all the data from the table, can't I do something like fields=null? or fields=all?

              – Jenny From the Block
              Mar 29 at 1:15











            • @JennyFromtheBlock I've updated my answer. If the client doesn't specify a parameter of fields ( that means fields==null or fields.Count==0), we will export all the fields.

              – itminus
              Mar 29 at 1:37












            • I can't thank you enough! I have learned a lot! I hope this helps others as well!

              – Jenny From the Block
              Mar 29 at 2:03

















            • Oh my God @itminus! It worked so well!. Thank you so much for the assistance.

              – Jenny From the Block
              Mar 29 at 1:14











            • If I were wanting to export all the data from the table, can't I do something like fields=null? or fields=all?

              – Jenny From the Block
              Mar 29 at 1:15











            • @JennyFromtheBlock I've updated my answer. If the client doesn't specify a parameter of fields ( that means fields==null or fields.Count==0), we will export all the fields.

              – itminus
              Mar 29 at 1:37












            • I can't thank you enough! I have learned a lot! I hope this helps others as well!

              – Jenny From the Block
              Mar 29 at 2:03
















            Oh my God @itminus! It worked so well!. Thank you so much for the assistance.

            – Jenny From the Block
            Mar 29 at 1:14





            Oh my God @itminus! It worked so well!. Thank you so much for the assistance.

            – Jenny From the Block
            Mar 29 at 1:14













            If I were wanting to export all the data from the table, can't I do something like fields=null? or fields=all?

            – Jenny From the Block
            Mar 29 at 1:15





            If I were wanting to export all the data from the table, can't I do something like fields=null? or fields=all?

            – Jenny From the Block
            Mar 29 at 1:15













            @JennyFromtheBlock I've updated my answer. If the client doesn't specify a parameter of fields ( that means fields==null or fields.Count==0), we will export all the fields.

            – itminus
            Mar 29 at 1:37






            @JennyFromtheBlock I've updated my answer. If the client doesn't specify a parameter of fields ( that means fields==null or fields.Count==0), we will export all the fields.

            – itminus
            Mar 29 at 1:37














            I can't thank you enough! I have learned a lot! I hope this helps others as well!

            – Jenny From the Block
            Mar 29 at 2:03





            I can't thank you enough! I have learned a lot! I hope this helps others as well!

            – Jenny From the Block
            Mar 29 at 2:03













            0
















            if you want to use the datatable then we can define which you need to select from the datatable in this way



            string[] selectedColumns = new[] "Column1","Column2";
            DataTable dt= new DataView(fromDataTable).ToTable(false, selectedColumns);


            or else if you wanna you list then you can use linq for selection of particular columns



            var xyz = from a in prod.Categories
            where a.CatName.EndsWith("A")
            select new CatName=a.CatName, CatID=a.CatID, CatQty = a.CatQty;





            share|improve this answer





























              0
















              if you want to use the datatable then we can define which you need to select from the datatable in this way



              string[] selectedColumns = new[] "Column1","Column2";
              DataTable dt= new DataView(fromDataTable).ToTable(false, selectedColumns);


              or else if you wanna you list then you can use linq for selection of particular columns



              var xyz = from a in prod.Categories
              where a.CatName.EndsWith("A")
              select new CatName=a.CatName, CatID=a.CatID, CatQty = a.CatQty;





              share|improve this answer



























                0














                0










                0









                if you want to use the datatable then we can define which you need to select from the datatable in this way



                string[] selectedColumns = new[] "Column1","Column2";
                DataTable dt= new DataView(fromDataTable).ToTable(false, selectedColumns);


                or else if you wanna you list then you can use linq for selection of particular columns



                var xyz = from a in prod.Categories
                where a.CatName.EndsWith("A")
                select new CatName=a.CatName, CatID=a.CatID, CatQty = a.CatQty;





                share|improve this answer













                if you want to use the datatable then we can define which you need to select from the datatable in this way



                string[] selectedColumns = new[] "Column1","Column2";
                DataTable dt= new DataView(fromDataTable).ToTable(false, selectedColumns);


                or else if you wanna you list then you can use linq for selection of particular columns



                var xyz = from a in prod.Categories
                where a.CatName.EndsWith("A")
                select new CatName=a.CatName, CatID=a.CatID, CatQty = a.CatQty;






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 28 at 6:29









                Ravi KanthRavi Kanth

                5956 silver badges26 bronze badges




                5956 silver badges26 bronze badges






























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55389349%2fexport-file-with-asp-net%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현