how save images in server side

Posted by Chanti444 under ASP.NET on 10/15/2011 | Points: 10 | Views : 2103 | Status : [Member] | Replies : 4
hi..........
.
how to save images in server side and how to retrive that images from front end.

pls help me if u have any example send me...................

satya


Responses

Posted by: Jayakumars on: 10/15/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

friend

refer this

http://www.dotnetfunda.com/forums/thread6359-how-to-bind-images-to-image-control.aspx

Mark as Answer if its helpful to you

Chanti444, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vforvijay on: 10/19/2011 [Member] Starter | Points: 25

Up
0
Down
HI...Refer the below link.......
http://vbdotnetaddict.blogspot.com/2011/06/how-to-retrieve-uploaded-images-from.html

Chanti444, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mittaikariss on: 10/19/2011 [Member] Bronze | Points: 25

Up
0
Down
Refer this link..........
http://www.dotnetfunda.com/codes/code1750-how-to-image-insert-to-database.aspx


http://www.invomtech.com/

....sundarsowmia....

Chanti444, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Arun.padmanaban on: 10/20/2011 [Member] Starter | Points: 25

Up
0
Down
:   <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="imagesave_in_database._Default" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style4
{
width: 176px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:TextBox ID="txtName" runat="server" Width="95px">
</asp:TextBox>
<table>
<tr>
<td class="style4">
<asp:FileUpload ID="FileUpload1" runat="server" Style="z-index: 1; left: 254px; top: 153px;
position: absolute" />
</td>
</tr>
<tr>
<td class="style4">
<asp:Button ID="Button1" runat="server" Style="z-index: 1; left: 263px; top: 187px;
position: absolute; width: 50px;" Text="upload" OnClick="Button1_Click" />
</td>
</tr>
</table>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID"
EnableModelValidation="True">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
SortExpression="ID" />
<asp:BoundField DataField="ImageName" HeaderText="ImageName" SortExpression="ImageName" />
<asp:TemplateField HeaderText="Image">
<ItemTemplate>
<asp:Image ID="Image1" runat="server" ImageUrl='<%# "Handler.ashx?ID=" + Eval("ID")%>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [ID], [ImageName], [Image]
FROM [Images]"></asp:SqlDataSource>
</form>
</body>
</html>





Code: aspx.cs
protected void Button1_Click(object sender, EventArgs e)
{
string strImageName = txtName.Text.ToString();
if (FileUpload1.PostedFile != null && FileUpload1.PostedFile.FileName != "")
{
byte[] imageSize = new byte[FileUpload1.PostedFile.ContentLength];
HttpPostedFile uploadedImage = FileUpload1.PostedFile;
uploadedImage.InputStream.Read(imageSize, 0, (int)FileUpload1.PostedFile.ContentLength);

// Create SQL Connection
SqlConnection con = new SqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

// Create SQL Command

SqlCommand cmd = new SqlCommand();
cmd.CommandText = "INSERT INTO Images(ImageName,Image) VALUES (@ImageName,@Image)";
cmd.CommandType = CommandType.Text;
cmd.Connection = con;

SqlParameter ImageName = new SqlParameter("@ImageName", SqlDbType.VarChar, 50);
ImageName.Value = strImageName.ToString();
cmd.Parameters.Add(ImageName);

SqlParameter UploadedImage = new SqlParameter("@Image", SqlDbType.Image, imageSize.Length);
UploadedImage.Value = imageSize;
cmd.Parameters.Add(UploadedImage);
con.Open();
int result = cmd.ExecuteNonQuery();
con.Close();
if (result > 0)
// lblMessage.Text = "File Uploaded";
GridView1.DataBind();

}
}


Chanti444, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response