damienbod / aspnetcorecsvimportexport Goto Github PK
View Code? Open in Web Editor NEWASP.NET Core CSV import export custom formatters
Home Page: https://damienbod.com/2016/06/17/import-export-csv-in-asp-net-core/
ASP.NET Core CSV import export custom formatters
Home Page: https://damienbod.com/2016/06/17/import-export-csv-in-asp-net-core/
These should really be one single repository.
Right now for example there is a code difference between the CsvInputFormatter
s in both packages.
It does not seem smart to try and maintain both of these and keep them up to date. We should just create a Samples folder and put this entire project in it and then bring over the NuGet bits.
This works great. I want to pass the query parameters to this get method and export data.csv. Is there a way to do it?
Line 123 of the CsvOutputFormatter will truncate everything in the line until the last null value property. It should be changed to
_valueLine = string.Concat(_valueLine, string.Empty, _options.CsvDelimiter);
Question: In the CsvOutputFormatter, why did you call “GetValue(obj, null)” on the PropertyInfo objects instead of just using “GetValue(obj)”?
How about putting this into a NuGet package? i.e. the inputformatter and outputformatter.
Is it possible to update the NuGet package with the .NET Core 3.0 updates in the repo?
https://www.nuget.org/packages/WebApiContrib.Core.Formatter.Csv/
Hi damienbod,
Thanks for a great library. I have a question:
I have a class with 10 properties. I would like to export to CSV only 5 properties and ignore 5. How could we achieve that?
Something like an attribute on the top of property such as
[CsvIgnore]
public bool NewProduct {get; set;}
Thanks
Hi Damien,
I tried your code but struggle with getting the upload done from the User Interface. I tried with Kendo UI to Upload to the Import URL but as List<LocalizationRecord> value
I get count == 0
.
Could you help me ?
Html Code snippet:
<div id="example">
<div class="box">
<h4>Information</h4>
<p>
The Upload can be used as a drop-in replacement
for file input elements. This "synchronous" mode does not require
special handling on the server.
</p>
</div>
<form method="post" action="/api/csvtest/import">
<div class="demo-section k-content">
<input name="files" id="files" type="file" aria-label="files" />
<p style="padding-top: 1em; text-align: right">
<input type="submit" value="Submit" class="k-button k-primary" />
</p>
</div>
</form>
<script>
$(document).ready(function() {
$("#files").kendoUpload();
});
</script>
</div>
Thanks,
Erich
System.InvalidCastException was unhandled by user code
HResult=-2147467262
Message=Unable to cast object of type 'AspNetCoreCsvImportExport.Model.LocalizationRecord' to type 'System.Collections.IList'.
Source=AspNetCoreCsvImportExport
StackTrace:
at AspNetCoreCsvImportExport.Formatters.CsvInputFormatter.readStream(Type type, Stream stream) in C:\projects\AspNetCoreCsvImportExport\AspNetCoreCsvImportExport-master\src\AspNetCoreCsvImportExport\Formatters\CsvInputFormatter.cs:line 71
at AspNetCoreCsvImportExport.Formatters.CsvInputFormatter.ReadRequestBodyAsync(InputFormatterContext context) in C:\projects\AspNetCoreCsvImportExport\AspNetCoreCsvImportExport-master\src\AspNetCoreCsvImportExport\Formatters\CsvInputFormatter.cs:line 37
at Microsoft.AspNetCore.Mvc.Formatters.InputFormatter.ReadAsync(InputFormatterContext context)
at Microsoft.AspNetCore.Mvc.ModelBinding.Binders.BodyModelBinder.d__3.MoveNext()
InnerException:
Is there any, easy, way to serve the CSV with a custom datetime formatting?
Hello,
I have been using you code for exporting data from an IQueryable into a CSV file and it works fine.
I just would like to know how can I parametrize the Save window? For example, by giving a default file name (for the time being it's taking the name of my controller without the file extension), Save as type?
Thank you
Sylvain
System.InvalidCastException: Unable to cast object of type 'report_engine.Models.CustomerPlanModel' to type 'System.Collections.IList'
On line 68 of CsvInputFormatter.cs
list = (IList)Activator.CreateInstance(itemType);
Not sure why, my class is simple it's just two string properties...
public class CustomerPlanModel
{
public string CustomerNumber { get; set; }
public string PlanId { get; set; }
}
Note I did change the CsvDelimeter to "," instead of ";" and I am POSTing over:
CustomerNumber,PlanId
CUS-091090129301823,1420fosj
CUS-019209123,fdsojwi3
CUS-91302920139,dsds908
Edit: tried using ";" as the original code does and it still gave me the same error...
[
{
"id": 1,
"name": "Tom",
"products": [
{
"id": 10,
"name": "car"
},
{
"id": 11,
"name": "truck"
},
]
},
{
"id": 2,
"name": "Dave",
"products": [
{
"id": 10,
"name": "car"
}
]
}
]
employee_id,employee_name,employee_products1_id,employee_products1_name,employee_products2_id,employee_products1_name
1,Tom,10,Car,11,Truck
2,Dave,10,Car,,
Can we see an example of how to respond as a file? Is it as easy as setting this? https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition
Hi I am importing files from an external FTP site, often the file headers are not known ahead of time. And, I need to save into a temp db stable in sql.
Here i ma using your project to help me. But I am running into an issue where the file headers are not know ahead of time, can we emit "genric" models.
I can adding my code here to build a generic db sql table to help others as well. I just need help on the import side
thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.