473,804 Members | 2,747 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 = uploadedFileFie ld.PostedFile
imageToCheck.Co ntentType
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 1455
"Darrel" wrote ...
imageToCheck = uploadedFileFie ld.PostedFile
imageToCheck.Co ntentType
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(strFilePa th, 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******** *****@TK2MSFTNG P05.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
1716
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 great. Any way to create an image (in asp.net on the server) of full web page - text and all. Currently I have dynamic on top of that image and can
2
11977
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 of system.drawind.image...what gives?!? tia,
6
2148
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 matter what icons are loaded. The first always shows up and any icons after that give me the error. Here is the offending code: The "DestinationPath" variable is the full path and filename of the icon
15
5371
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 path of the uploaded image, and resize it with the provided dimensions. My function is below. The current function is returning an error when run from the upload function: A generic error occurred in GDI+. Not sure what exactly that means. From what...
4
3061
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 says: "Invalid parameter used". The gif an bmp files are valid image files, I can open them in any graphics software and windows can do the preview.
5
3378
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, when I did this I got the following error: 'System.Drawing.Image.Image()' is inaccessible due to its protection level Looking at other online examples, I found that the proper way to use it is like this:
6
7612
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. Is there a way to determine image type in the .net framework? Thanks.
14
16367
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 ImageFromFileReleaseHandle(string filename) { FileStream fs = null; try {
2
5685
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, hourglass, etc.) I've tried the following: - Comparing the IntPtr to C#'s predefined cursor types (i.e. Cursors.Arrow.CopyHandle()) - Comparing the IntPtr to another IntPtr obtained using the WINAPI function LoadCursor
0
9711
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10343
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10087
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9166
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7631
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5667
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4306
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.