Checking image type of an image grabbed fromfile

D

Darrel

When I accept an image that has been uploaded through a form, I can grab the
image type as such:

imageToCheck = uploadedFileField.PostedFile
imageToCheck.ContentType
If (contentType = "image/pjpeg") _
Or (contentType = "image/jpeg") _
etc...

I'm now trying to figure out how to get the contentType from an image
fromfile:

System.Drawing.Image.FromFile("path/file.jpg")

Can that be done? I don't see a 'contentType' property for that type of
object.

-Darrel
 
R

Rob Meade

...
imageToCheck = uploadedFileField.PostedFile
imageToCheck.ContentType
If (contentType = "image/pjpeg") _
Or (contentType = "image/jpeg") _
etc...
Can that be done? I don't see a 'contentType' property for that type of
object.

Hi Darrel,

I'm sure there's a better way than this, but if you're using If..Then's in
the top example you posted, why not just do the same for the files on the
server? You obviously know what type of files you are going to be
receiving...

Select Case Right(strFilePath, 4)

Case ".gif"

Case ".jpg"

End Select

etc etc..

You could always store this information in a config file or database table,
populated when they upload, so whenever a new one is uploaded, you are still
able to support it.

Regards

Rob
 
D

Darrel

You could always store this information in a config file or database
table, populated when they upload, so whenever a new one is uploaded, you
are still able to support it.

I could just check the file extension. Is that all that is uses to check
'contenttype' to begin with? I thought contenttype was a bit more specific,
IE, if I saved a GIF file with a JPG extension, contenttype would still know
it's really a GIF.

-Darrel
 
R

Rob Meade

...
I could just check the file extension. Is that all that is uses to check
'contenttype' to begin with?

I dont think so.
I thought contenttype was a bit more specific, IE, if I saved a GIF file
with a JPG extension, contenttype would still know it's really a GIF.

That was my understanding yes, so you could grab this out during upload,
save it to your database, and then use it to compare future uploads at a
later date.

Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top