Find centralized, trusted content and collaborate around the technologies you use most. Connect and share knowledge within a single location that is structured and easy to search. NET core Api. The pdf file is stored in SQL server. I tried a number of ways posted in stackoverflow but none of the ones works for me.
Some examples download a pdf file but if It was tried to open, It caught an error '.. As you can see from my above sample codes that it works if a pdf in varbinary Max is downloaded directly using SQLCommand but doesn't work if a pdf is downloaded via API. I am suspecting that API returns byte[] in Json format. Student photos are displayed successfully via the api without any issue but downloading Pdf file doesn't work.
What causes downloaded PDF files corrupted in my codes? When you return byte[] from ASP. NET Core action it's result is base64 encoded and that's why you get a "corrupted" file. You have to return FileResult from action in order to let the framework process binary data properly. TransmitFile retrieves a file and writes it to the Response. In some cases, we can't call TransmitFile because we can't map a path to the file. Instead, we'll get the file as a Stream and write it to the Response object: Response.
Open, FileAccess. Read buffer, 0, bufferLength ; Response. Flush ; Response. The project download includes working examples of both of these techniques. Accept Solution Reject Solution. Posted Jan pm chandrashekhar racharla. Member Jan pm. Copy Code. Posted Jan pm amolpatil Posted Jan pm Manoj Kumar Choubey. TransmitFile Server. Flush ; Response. Hi how to download file using c my file is stored in a folder and only file path is saved on database when i download file like.
I am using the solution no 4 but one of our server it is not downloading. Is there any configuration issue. I tried with static compression disable enable.
Add your solution here. There are some more code examples in these threads you can refer to. NET ] [ How to download file with asp. NET file download from serve r] Hope these are helpful to you.
Best Regards, Daniel Zhang. This can be beneficial to other community members reading this thread. The content you requested has been removed. Ask a question. Quick access. Search related threads. Remove From My Forums. Asked by:. Archived Forums.
0コメント