Solved

save image file in ASP 2.0 using C#

Posted on 2007-11-21
8
2,200 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 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

13 Experts available now in Live!

Get 1:1 Help Now