473,395 Members | 2,783 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Checking image type of an image grabbed fromfile

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
Jul 17 '06 #1
4 1428
"Darrel" wrote ...
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
Jul 17 '06 #2
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
Jul 17 '06 #3
You need a solution like this..

http://www.netomatix.com/Products/Do...eDetector.aspx

"Darrel" <no*****@nospam.comwrote in message
news:uI*************@TK2MSFTNGP05.phx.gbl...
>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

Jul 17 '06 #4
"Darrel" wrote ...
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
Jul 20 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: jason | last post by:
Hello. This one is kinda out there. I have asp.net code that will email my yahoo account a <img> like with image on the server. When I open it in yahoo I get the full image on screen. works...
2
by: steve | last post by:
imports system.drawing imports system.drawing.image dim img as image = image.fromfile("a.bmp") picturebox1.image = img i'm using vs 2003 and the error i have is that fromfile is not a member...
6
by: Patrick Dugan | last post by:
Hello, I'm trying to load different images (icons) into a PictureBox1.Image. The first image loads just fine, but the second image always returns the error "Invalid property used." It doesn't...
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
4
by: escristian | last post by:
Hello. I'm trying to create an Image so I use something like this: Image newImage = Image.FromFile(filename); Now when it's a bmp file and certain .gif files it gives me an exception that...
5
by: Jerry J | last post by:
I want to use the System.Drawing.Image class. According to the help file, this is an abstract base class. Because it is supposedly abstract, I created another class that inherits from it. However,...
6
by: Frank Rizzo | last post by:
I have an interesting problem. I have a directory of image files. However, none of the files have an extension. I need to figure out what type if image it is and attach an extension to the file. ...
14
by: Steve K. | last post by:
I have a method that I use to get a System.Drawing.Image from a file without keeping a handle on the file open (so I can delete the file). Here is the code: <code> public static Image...
2
by: ACS | last post by:
I have a C# application where I've grabbed a control's cursor handle using the WINAPI function GetCursor(). This returned an IntPtr and I want to check what type of cursor this is (arrow, sizing,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.