FileHelpers | NET library to read/write data | CSV Processing library
kandi X-RAY | FileHelpers Summary
kandi X-RAY | FileHelpers Summary
The FileHelpers are a free and easy to use .NET library to read/write data from fixed length or delimited records in files, strings or streams
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of FileHelpers
FileHelpers Key Features
FileHelpers Examples and Code Snippets
Community Discussions
Trending Discussions on FileHelpers
QUESTION
I'm building an ASP.NET Core 6.0 web API. The API has endpoints that take in multipart/form-data
requests and save the sections into files. If the internet connection gets cut during the handling of the request the following error is logged into the application's console:
Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException: Unexpected end of request content. at Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException.Throw(RequestRejectionReason reason) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1ContentLengthMessageBody.ReadAsyncInternal(CancellationToken cancellationToken) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpRequestStream.ReadAsyncInternal(Memory 1 buffer, CancellationToken cancellationToken) at Microsoft.AspNetCore.WebUtilities.BufferedReadStream.EnsureBufferedAsync(Int32 minCount, CancellationToken cancellationToken) at Microsoft.AspNetCore.WebUtilities.MultipartReaderStream.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken) at System.IO.Stream.CopyToAsyncInternal(Stream destination, Int32 bufferSize, CancellationToken cancellationToken) at AppName.Utilities.FileHelpers.ProcessStreamedFile(MultipartSection section, ContentDispositionHeaderValue contentDisposition, IConfiguration conf, ModelStateDictionary modelState, CancellationToken ct) in C:\AppName\Utilities\FileHelpers.cs:line 153
After the connection is restored, new requests from the same machine used to send the failed request are not handled by the application unless the application is restarted. This happens for all API endpoints, not just for the failed ones. Postman requests from localhost go through as they should.
My question is: what causes the API to get stuck this way? I don't understand why and how the loss of connection causes the application to stop receiving new requests from the remote machine.
Here is the code I'm using to handle the multipart, this function is called in the controller for the multipart POST requests. It goes through the multipart sections and calls ProcessStreamedFile
for each of them. It has other functions as well that I can not share here but nothing related to IO or HTTP communication.
ANSWER
Answered 2022-Apr-04 at 08:27This issue was caused by a port-forwarding I was using to make the connection. Due to our network configuration, I had to initially use a Putty tunnel and forward the remote machine's (the one sending the request) port to my local computer (running the server). Somehow this tunnel gets stuck when the connection is lost. Now I was able to change our network so that I can send the request directly to my local machine by using the actual public IP and everything works well.
I am not sure why the Putty tunnel gets stuck but as of now I am able to avoid the problem and can't dig deeper due to time constraints.
QUESTION
I have an API method that streams uploaded files directly to disk to be scanned with a virus checker. Some of these files can be quite large, so IFormFile is a no go:
Any single buffered file exceeding 64 KB is moved from memory to a temp file on disk. Source: https://docs.microsoft.com/en-us/aspnet/core/mvc/models/file-uploads?view=aspnetcore-3.1
I have a working example that uses multipart/form-data and a really nice NuGet package that takes out the headache when working with multipart/form-data, and it works well, however I want to add a file header signature check, to make sure that the file type defined by the client is actually what they say it is. I can't rely on the file extension to do this securely, but I can use the file header signature to make it at least a bit more secure. Since I'm am streaming directly to disk, how can I extract the first bytes as it's going through the file stream?
...ANSWER
Answered 2021-Jun-22 at 13:51You may want to consider reading the header yourself dependent on which file type is expected
QUESTION
This answer shows a nice way to use CsvHelper with generic F# option types. How do you do the same thing with FileHelpers?
I cannot figure out how to make the generic OptionConverter work. Consider the following test.csv
:
ANSWER
Answered 2021-Feb-27 at 22:16The problem is in your StringToField
method. The static type returned by Convert.ChangeType
is obj
, so the resulting option has type Option
, rather than Option
. To fix this, downcast the converted value before calling Some
:
QUESTION
I am thinking of something like a config, xml, or JSON file. But I have not found any such solution. Perhaps FileHelpers doesn't have this functionality outside of the compiled assembly, but this is a long shot in the dark. The situation is that I have several files to read from and/or to write to, that quite often change structures slightly; and also the need to add new ones to interact with when new customers are acquired. I have used the FileHelpers library succesfully before, but for the sake of not having to recompile a rather large application every time a customer changes their file structure, or a new one starts doing business with us, I need to be able to add, remove, or alter the FileHelpers structure class of a CSV, Excel, or TXT file (depending on customer needs), rather dynamically. Any guidance will be appreciated.
...ANSWER
Answered 2020-Sep-19 at 00:18You can generate C# classes and compile them at runtime based on structure defined in a configuration file. See this SO question for different ways of doing it including the use of Roslyn toolset.
Another, perhaps easier approach will be giving FileHelper's own Smart Format Detector a try.
While you can pursue this path and eventually succeed, it seems that requirements of your system (customers that change their CSV structure now and then, new customers with new file structures, etc.) calls for using a different library that doesn't need pre-defined classes to read CSV data and can access each row and column on demand. You can have metadata about format of each customer's file, and read/write data flexibly on the fly.
QUESTION
I have a datetime as string 2020-05-14T13:37:49.000+0000, I need convert to DateTime using C#.
Which is the valid format ? yyyy-MM-ddTHH:mm:ss.FFFZ wrong for me
...ANSWER
Answered 2020-Jun-15 at 13:59You should use K
format specifier, since it represents timezone offset
QUESTION
I am creating an API endpoint for uploading large files. These should not be buffered in memory (at least not in their entirety), and will be streamed directly to the DB or to disk.
There are official Microsoft docs on streaming uploads to DB, but it does not show how to ensure in an unbuffered way that you don't read files larger than the limit. (The code in the sample repo has a helper that checks this by reading the entire file into memory, which defeats the purpose of streaming in the first place.)
Is there a (preferably simple) way to make the streaming fail when it reads more bytes than some specified limit? Are there perhaps other ways to ensure that users can't upload too large files?
...ANSWER
Answered 2020-Jun-08 at 14:02This issue explains how to set size limits globally and per request when using Kestrel.
Per request using attribute:
QUESTION
I am attempting to write a check in my Cake build script to pull in a file from BuildParameters
and check if the file contents are empty -- if contents are empty, throw an exception and quit the build.
I am attempting to use FileReadText
from the FileHelpers
namespace but for some reason I cannot get my build to recognize the file command. I am following the syntax and documentation found here: https://cakebuild.net/api/Cake.FileHelpers/FileHelperAliases/97F5679A
Here is the code I am trying in build.cake
:
ANSWER
Answered 2020-Feb-26 at 22:05Have you added the #addin pre-processor directive, as mentioned here:
https://github.com/cake-contrib/Cake.FileHelpers/#cakefilehelpers
You can easily reference Cake.FileHelpers directly in your build script via a cake addin:
#addin "Cake.FileHelpers"
QUESTION
I am having trouble accessing files saved in getApplicationDocumentsDirectory
on android only, I keep locale, theme and assets files stored there and when booting up the app those files are always inaccessible and as a result the app does not load, I tried using shared_prefs
to track a first load scenario to use the files in assets/
and then later use the ones download but that seems to be an unreliable fix as at 2nd run they also inaccessible.
The only thing that seems to work reliable is the theme.json, but both copy functions run through the same helpers so what copies the theme over is what copies the locale over. Theme is loaded up in main.dart but the locale is loaded up with EasylocaLizationDelegate
and if the files are in Document storage it can never load them up.
None of these issues are present on iOS, does anyone know of any special tricks to make this work for android, I have tried google but not really sure what to search for.
...ANSWER
Answered 2020-Feb-24 at 08:52I eventually realised that while not an issue on iOS, using rootBundle.loadString
does not work for document storage on Android.
I needed to replace that bit with
QUESTION
I upgraded my .net core 2.2 web api to .net core 3.1. I am now able to run it from console using dotnet myapi.dll
, however when I try to host it on ISS, I get following exception.
I have installed AspNetCore Module V2
and this module is throwing exception and I am not able to understand the missing part.
Autofac.Core.DependencyResolutionException: An exception was thrown while activating ?:Microsoft.Extensions.Hosting.IHostedService[] -> Microsoft.AspNetCore.Hosting.GenericWebHostService -> Microsoft.AspNetCore.Server.IIS.Core.IISHttpServer.
---> Autofac.Core.DependencyResolutionException: An exception was thrown while invoking the constructor 'Void .ctor(Microsoft.AspNetCore.Server.IIS.Core.IISNativeApplication, Microsoft.Extensions.Hosting.IHostApplicationLifetime, Microsoft.AspNetCore.Authentication.IAuthenticationSchemeProvider, Microsoft.Extensions.Options.IOptions``1[Microsoft.AspNetCore.Builder.IISServerOptions], Microsoft.Extensions.Logging.ILogger
Following is my Program.cs
ANSWER
Answered 2020-Feb-10 at 16:07Remove the Microsoft.AspNetCore.* nuget packages, those no longer exist in 3.0 so you're pulling in 2.x versions. https://docs.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.1&tabs=visual-studio#remove-obsolete-package-references
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install FileHelpers
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page