Click here to Skip to main content
15,743,299 members
Please Sign up or sign in to vote.
1.57/5 (3 votes)
See more:
can you please give me a proper code in (c# web devolpment) to upload all types of images(.jpg,.gif,.png,bmp etc..)
i got the code but it only uploads images of the format jpg..
i want to know, is there any problem to upload images of the format other than jpg??
and also i want the code which would not allow to upload any duplicate image..


moreover i will store that image name on database and when i would upload the image, i would like to show it on an image control
but because i am uploading only single image so i do not want to use any fully data bound controls like (Gridview,repeater or any other)..
how to do it??
thanks :)
Posted
Updated 26-Jan-10 17:23pm
v2

arvinder_aneja wrote:
i got the code but it only uploads images of the format jpg..


That is impossible. A web app uploads any file you like, through a control that doesn't care what sort of file it is dealing with. That's the only option in HTML, and therefore in ASP.NET.

Use the ASP.NET tag to let people know if you're writing a web app.


arvinder_aneja wrote:
and also i want the code which would not allow to upload any duplicate image..


you can check if the same filename has been used, but you can't easily tell if two images are exactly the same image, that is, not without a bit of code and a bit of time for larger images.

arvinder_aneja wrote:
moreover i will store that image name on database and when i would upload the image, i would like to show it on an image control


OK, that's easy

arvinder_aneja wrote:
but because i am uploading only single image so i do not want to use any fully data bound controls like (Gridview,repeater or any other)..


To show images in a data bound control, you'd create a template for a column that shows an img tag, or an asp:Image tag, and binds the image path to the control. If you only want to show a single image, you'd just have a single img or asp:Image control, and bind that to the single path that you have to work with, there's literally no difference in the task, the only difference is adding a step to make it work with many images through a dataset.

Just to add, I appreciate you stating that you're writing a web app, and using real English to ask your question. Please just use the ASP.NET tag as well as C#, so that if people are filtering for questions to answer, they will find yours. It's really only for your benefit that I ask this.
 
Share this answer
 
v2
Please don't post answers to your own question, unless you really have the answer to post. Use the forum below, or edit your post.

The code is very trivial. You say you have code but it only works for jpg. You should post that code ( you should ALWAYS post your code when asking people to help you with it ). The duplicate image thing, you need to clarify if you mean image path ( which is a problem, why can't two people upload two different images both called cat.jpg ), or two identical images, which poses it's own problems. You should read my image processing articles if you want to do that, you'd need to iterate over the whole image and compare it pixel by pixel, or decide on what sample you're willing to accept as proof that they are the same. What if I resize the same image and upload it, will you accept that ? The question needs to be defined before it can be answered.

<asp:Image runat="server" ID="image"/>

and then when your file is uploaded, you save it and set image.ImageUrl to the path you saved it at, that's the grand total of the answer to your last question, as I said, that's so trivial, that I think it's more worthwhile to explore what you have first, then ask where you've learned from, to not be able to work out basics like that using your references and/or google.
 
Share this answer
 
thanks for your support..
but i want the proper code to do this..
or i want the link where i can find this...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900