C Contenttype Pdf

  1. C Content Type Pdf Free
  2. Content-type Application/x-pdf
  3. C Content Type Pdf Download
Active2 months ago

I am creating a console application that

ContentType is used with the Attachment class to specify the type of content in the attachment. The syntax of the Content-Type header is described in RFC 2045 Section 5.1. RFC 2046 provides detailed information about MIME media types and their parameters. The PDF file will be uploaded using FileUpload control and will be inserted into SQL Server Database Table. A GridView control will display the PDF file present in the SQL Server Database Table along with an option to download the selected PDF file from Database in ASP.Net. TAGs: ASP.Net, SQL Server, GridView. Dim contentType As String.

  1. Connects to a vendor API to pull voucher numbers for submitted expenses between two dates and
  2. Downloads a PDF copy of receipts submitted with the expense

The first part, I have working fine. I am able to connect to the Vendor API and parse out the returned XML to create an array of voucher numbers (needed to get the PDF images) using the following code:

Yes, there is likely a better way of doing this, but it works and returns the values I am expecting.

Now, what I am having trouble with, is when I connect back to the API to retrieve the file, I cannot seem to be able to download the file to a specified file path.

I can connect back to the API using

But I cannot seem to write the response to a valid file (PDF)

Here is a screen shot of my Autos window as I step through the code, where I would need to download the file:

My question is, from this point, how do I go about saving the file to my system?

I have tried to take the encoded response I get from doing Console.WriteLine(NewResponseString); and write it to a file using the System.IO.File.WriteAllLines() method, using a specified filepath/name, but this results in a blank file. I have also spent some time researching the depths of Google/Stackoverflow, but do not understand how to implement the results I find.

Any and all help would be greatly appreciated.

Tim
1,2082 gold badges19 silver badges33 bronze badges

C Content Type Pdf Free

Jeff BeeseJeff Beese
2732 gold badges4 silver badges16 bronze badges
Contenttype

4 Answers

So I think you need help with Streams. The returned HttpContent is actually a System.Net.Http.StreamContent instance which shows that you are getting content back. Its just a matter of getting the Stream (content) from that instance and saving that to a file.

I respectfully recommend that you do a little reading on how Streams work. This is a common construct in many languages that you will probably have to deal with again in the near future.

IgorIgor
46.1k4 gold badges59 silver badges117 bronze badges

First of all, are you sure there is a file to begin with? May I suggest using the open source library PdfSharp. I personally use it myself and it works great. As far as downloading the file, maybe this may help you...

Download Synchronously

user6454724

At first Create StreamReader from NewResponse

Then Define a StremaWriter to write into a file.

Content-type Application/x-pdf

Alternative Approach is

Atanu SarkarAtanu Sarkar

Use this code for download a pdf from the API. It will convert the string data to bytes and provide you the necessary solution.

Draken
2,6088 gold badges29 silver badges43 bronze badges
vishal singhvishal singh

C Content Type Pdf Download

Not the answer you're looking for? Browse other questions tagged c#.netasp.net-web-api or ask your own question.