I have a C# code. I have a C# API that have in response an array of bytes. I have to…
- User
I have a C# code. I have a C# API that have in response an array of bytes. I have to from that array of bytes turn it into excel file
- Assistant
Certainly! If you have a byte array coming from a C# API response, and you want to convert it into an Excel file, usually that byte array either represents the binary content of an Excel file (for example data), or it represents raw data you want to write into an Excel file.
- User
My C# API response have a class structure with field int code (response code), string message (response message), byte[] obj (ExcelBytes). I need to take excelBytes from response to turn into Excel File
- Assistant
Thanks for the details!
Since your API response class contains a
byte[] objwhich holds the Excel file bytes (the actual Excel file saved as bytes), the solution is very straightforward: you just need to extract that byte array from the response and write it directly to a file.Example: write the Excel bytes from response to a file
Assuming you have a class like this:
public class ApiResponse { public int code { get; set; } public string message { get; set; } public byte[] obj { get; set; } // Excel file bytes } - User
I have an error message Unexpected character encountered while parsing value: P. Path '', line 0, position 0
- Assistant
- User
I tried to do that request in swagger and i got error Failed to fetch. Possible Reasons: CORS Network Failure URL scheme must be "http" or "https" for CORS request.
- Assistant