A Content Type is how the server tells the browser what type of file the resource being served is.
Content type for text file in c#. The FileReadAllText method opens a text file reads all the text in the file into a string and then closes the file. The text content type is used for message content that is primarily in human-readable text character format. In most cases the following should work.
Read the first line of text line srReadLine. Considering you have text file at location DtestFiletxt you can use the below C Code in NET Core to read text file line by line. That way the browser knows how to render whether its HTML CSS JSON PDF etc.
ContentType ct new ContentType. If file already exists this method opens the file. If you will see the above code you will notice there isnt any difference in C Code when working with NET 45 or NET Core.
Add the attachment to the. What is a Content Type. Media-type Le type MIME de la ressource ou des données.
Read the next line line srReadLine. Is responding with header. Attachment data new Attachmentfs ct.
If you want to format text written to a file use the Format method or C string interpolation. The FileWriteAllLines writes a file one line at a time. The FileCreateText method creates and opens a file for writing UTF-8 encoded text.