Solved

save image file in ASP 2.0 using C#

Posted on 2007-11-21
8
2,204 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
application restarter  - for an exe that hangs 9 30
.NET 2008 VB and C# 6 39
defining NULL or 0 10 44
Unable to connect C# program to an SQL database - Exception occurs. 4 47
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

840 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