-
June 9th, 2018, 06:23 AM
#1
Img Collection
Hi,
In my ASP.NET Webform page, I have a fileuploader and a div. On single selection of image, the selected image is added to the div. All works fine. Now, I would like to add a checkbox or some sort of selection and then save the selected images to the server folder. Please can someone help on how to do it?
Thanks
-
December 21st, 2018, 05:23 AM
#2
Re: Img Collection
try this code:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"Inherits="Byte_array_gridview._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 id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<tr>
<td>
Image File </td>
<td>
<input id="Upload" type="file" runat="server" /></td>
</tr>
</table>
<asp:Button id="btn_insert" RunAt="server"
Text="Insert" onclick="btn_insert_Click"></asp:Button>
<asp:label id="lblMessage" runat="server" />
</div>
</form>
</body>
</html>
For image
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Data.SqlClient;
namespace Byte_array_gridview
{
public partial class image : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str;
SqlCommand com;
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "select photo from employee where id = '" + Request.QueryString["id"] + "'";
com = new SqlCommand(str, con);
MemoryStream stream = new MemoryStream();
byte[] image = (byte[])com.ExecuteScalar();
stream.Write(image, 0, image.Length);
Bitmap bitmap = new Bitmap(stream);
Response.ContentType = "image/Jpeg";
bitmap.Save(Response.OutputStream, ImageFormat.Jpeg);
con.Close();
stream.Close();
}
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|