Solved

save image file in ASP 2.0 using C#

Posted on 2007-11-21
8
2,202 Views
Last Modified: 2012-05-05
How could I save an image file in Sql server 2005? In my application, I want to save the image in a folder and then the directory in the sql server 2005. So, in my table, there will be sth like this ~/images/header1.jpg
and the header.jpg should go to images folder in my application.

Could somebody help?
0
Comment
Question by:siddhuoops
8 Comments
 
LVL 21

Expert Comment

by:surajguptha
ID: 20329262
You can store files as BLOBS in the database. In the database it wont be stored in folders but as its own internal representation
0
 
LVL 13

Expert Comment

by:SameerJagdale
ID: 20333019
do you mean, you want to save imagepath in a table and actual image in folder..
0
 

Author Comment

by:siddhuoops
ID: 20344492
yup
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 21

Expert Comment

by:surajguptha
ID: 20345977
Folders in the SQL database is not possible as far as i know if thats what you mean.
0
 

Author Comment

by:siddhuoops
ID: 20351380
I was able to save image in a sql database but now how would I display that image in an image control?
This is how I saved the image.
                byte[] sponsorimage = new byte[sponsorupload.PostedFile.ContentLength];
                HttpPostedFile Image = sponsorupload.PostedFile;
                Image.InputStream.Read(sponsorimage, 0, (int)sponsorupload.PostedFile.ContentLength);

                scon = new SqlConnection("Data Source=sadev01;Initial Catalog=Hometourads;Persist Security Info=False;User ID=sa_sql;Password=str@teg1K@m3r1ka");
                scmd = new SqlCommand("SA_STPR_Hometourads_Insert", scon);
                scmd.CommandType = CommandType.StoredProcedure;

                scmd.Parameters.AddWithValue("@sponsor_logo", sponsorimage);
                scon.Open();
                scmd.ExecuteNonQuery();
                scon.Close();
            }

            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            finally
            {
                scon.Close();
            }

Now I want to display this image in an image control. What should I have to do in order to display it?
0
 
LVL 21

Accepted Solution

by:
surajguptha earned 500 total points
ID: 20359662
Set the ImageControl's Image property to Image object that you constructed
0
 
LVL 1

Expert Comment

by:Vee_Mod
ID: 20516351
Force accepted.
Vee_Mod
Community Support Moderator
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Programmatically signing Word macros 4 61
Need to pass connection string through config 2 26
Replace &lt; with < 14 56
Help with C#, MVC, razor. 6 23
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now