how to identify the extension/type of the file using C#?

前端 未结 5 2005
迷失自我
迷失自我 2021-01-03 00:55

i have a workflow where user is allowed to upload any file and then that file will be read.

Now my question is if user have image file xyz.jpg and he renamed it to

5条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-03 01:25

    If you just need to see if the uploaded file is an Image, just parse it accordingly

    try
    {
    Image image = Bitmap.FromStream(fileData);
    }
    catch(Exception e)
    {
        // this isn't an image.
    }
    

提交回复
热议问题