I wanna find real content type of a file whose filetype is changed. For example: i have abc.xls file. When I change the " .xls " file extension to jpg, (abc.jpg) Content type changes aswell. After that i am checking the content type and it returns image/jpg. But i wanna know real content type. (application/ms-excel) Is it posible ? With C#
Asked
Active
Viewed 403 times
0
-
3Files don't have a "real content type". There's nothing intrinsic in a file which says "I am an Excel file". Some appilications' files do put particular values in particular places which you can recognise, [see here](https://en.wikipedia.org/wiki/List_of_file_signatures), but that's a case of knowing all of these different signatures and specifically looking for them. You'll also notice that e.g. xlsx, docx and zip have the same signature: this is because xlsx/docx files are actually zip archives containing a set of files - so you'll need to extract the zip and look inside – canton7 Dec 22 '21 at 13:12
-
Is the question "Given a file, how can I detect what Mime Type I should use in the Content-Type http header during an HTTP response or HTTP request file upload?" – gunr2171 Dec 22 '21 at 13:13
-
*Content type changes aswell* - renaming a file changes the bytes inside for you? It shouldn't.. – Caius Jard Dec 22 '21 at 13:42
-
1Tempted to vote this as a duplicate of https://stackoverflow.com/questions/29211263/how-to-identify-doc-docx-pdf-xls-and-xlsx-based-on-file-header - would you agree? – Caius Jard Dec 22 '21 at 13:44