Hello, I have a code which can pass value of data selected from a row of gridview to another page. The data will then be display in a textbox for updates and edits. It works fine with text and dates, but i was wondering whether it can even obtain the path
of the image? This is my code to store the image in database:
If you want to view the upload image on next page ,you must retrive the imgae bystes form database by using handler you can view the image in image control....
For more refer the below links to retrive the image from the database.....
The uploaded image is stored in memory not on disk. You can edit the image by getting it from the memory stream and if you are going to use System.Drawing classes, then you can use
System.Drawing.Image.FromStream method.
Barcode, Labeling, Printing & Imaging tools for ASP.NET Developers
I want to be able to view the path in the textbox when I pass the hyperlink, like this: But I am unsure on what variable to write to pass the value from the previous page and the sql database
userid = Convert.ToInt32(Request.QueryString["ID"].ToString());
if (!IsPostBack)
{
BindControlvalues();
}
}
private void BindControlvalues()
{
con = new SqlConnection(connString);
con.Open();
cmd = new SqlCommand("select * from Table_1 where ID=" + userid, con);
da = new SqlDataAdapter(cmd);
con.Close();
ds = new DataSet();
da.Fill(ds);
title.Text = ds.Tables[0].Rows[0][1].ToString(); //title
string date = Convert.ToString(ds.Tables[0].Rows[0][4]);
pub.Text = DateTime.Parse(date).ToString("yyyy-MM-dd"); //date
Editor1.Content = ds.Tables[0].Rows[0][6].ToString(); //content
}
I'm sorry but I still do not understand what you want to do at the end. Look, when a file is uploaded, you get that through the PostedFile property which is an object of type
HttpPostedFile
That class features a couple of properties. One of them is FileName which is a the path
(on the client machine) of the uploaded file. To get and work on the uploaded file at the server side (your ASP.NET app) you need to use the InputStream property.
Barcode, Labeling, Printing & Imaging tools for ASP.NET Developers
What I am trying to do is display the path of the image, when edit is click, so that when the user doesnt change the image, it will still be displayed as the path is not change or the etxtbox is not empty
I think that based on all the messages above it's clear that with a posted file you have, #1 the path of the file (but on the client machine NOT on the server), and #2 the file binary content in the server's memory.
Barcode, Labeling, Printing & Imaging tools for ASP.NET Developers
colol
Member
117 Points
542 Posts
Query String on image bytes
Oct 09, 2012 06:52 AM|LINK
Hello, I have a code which can pass value of data selected from a row of gridview to another page. The data will then be display in a textbox for updates and edits. It works fine with text and dates, but i was wondering whether it can even obtain the path of the image? This is my code to store the image in database:
protected void Button1_Click(object sender, EventArgs e) { String Back = "Default.aspx"; 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); SqlConnection con = new SqlConnection(); con.ConnectionString = ConfigurationManager.ConnectionStrings["Sql"].ConnectionString; SqlCommand cmd = new SqlCommand(); cmd.CommandText = "Insert Into Table_1 (Title, Summary, Thumbnail) Values (@Title,@Summary,@Thumbnail)"; cmd.CommandType = CommandType.Text; cmd.Connection = con; cmd.Parameters.AddWithValue("Title", first.Text); cmd.Parameters.AddWithValue("Summary", sec.Text); SqlParameter UploadedImage = new SqlParameter("@Thumbnail", SqlDbType.Image, imageSize.Length); UploadedImage.Value = imageSize; cmd.Parameters.Add(UploadedImage); con.Open(); int result = cmd.ExecuteNonQuery(); con.Close(); if (result > 0) bindgrid(); } Label2.Text = "Succesfully upload. <a style='color: red' href=" + Back + ">" + " Back" + "</a>"; textbox.Visible = false; ClearFields(Form.Controls); } <tr> <td class="td1"><div align="right"><span>Thumbnail: </span></div></td> <td class="style1"> </td> <td class="td1"><div align="left"><span> <asp:FileUpload ID="FileUpload1" runat="server" /> </span></div></td> </tr>And this is my code to pass the values:
SqlConnection con; SqlDataAdapter da; SqlCommand cmd; DataSet ds; DataTable dt = new DataTable(); string connString = ConfigurationManager.ConnectionStrings["Sql"].ConnectionString; private int ID = 0; private int userid = 0; protected void Page_Load(object sender, EventArgs e) { userid = Convert.ToInt32(Request.QueryString["ID"].ToString()); if (!IsPostBack) { BindControlvalues(); } } private void BindControlvalues() { con = new SqlConnection(connString); con.Open(); cmd = new SqlCommand("select * from Table_1 where ID=" + userid, con); da = new SqlDataAdapter(cmd); con.Close(); ds = new DataSet(); da.Fill(ds); title.Text = ds.Tables[0].Rows[0][1].ToString(); //title string date = Convert.ToString(ds.Tables[0].Rows[0][4]); pub.Text = DateTime.Parse(date).ToString("yyyy-MM-dd"); //date }vijay_myl
Contributor
5070 Points
1068 Posts
Re: Query String on image bytes
Oct 09, 2012 07:08 AM|LINK
hi..
If you want to view the upload image on next page ,you must retrive the imgae bystes form database by using handler you can view the image in image control....
For more refer the below links to retrive the image from the database.....
http://www.dotnetcode.in/2011/06/how-to-retrieve-uploaded-images-from.html
My .NET blog
Submit Article
colol
Member
117 Points
542 Posts
Re: Query String on image bytes
Oct 09, 2012 09:00 AM|LINK
not exactly display, i would like its path so that I can edit/change the picture
Bala krishna...
Member
2 Points
2 Posts
Re: Query String on image bytes
Oct 09, 2012 09:05 AM|LINK
First get the path from the code,using that path you can display the image..
Neodynamic
Participant
1150 Points
316 Posts
Re: Query String on image bytes
Oct 09, 2012 11:27 AM|LINK
The uploaded image is stored in memory not on disk. You can edit the image by getting it from the memory stream and if you are going to use System.Drawing classes, then you can use System.Drawing.Image.FromStream method.
colol
Member
117 Points
542 Posts
Re: Query String on image bytes
Oct 10, 2012 12:45 AM|LINK
Is the PostedFile variable considered to be the memory stream?
colol
Member
117 Points
542 Posts
Re: Query String on image bytes
Oct 10, 2012 12:48 AM|LINK
I want to be able to view the path in the textbox when I pass the hyperlink, like this: But I am unsure on what variable to write to pass the value from the previous page and the sql database
userid = Convert.ToInt32(Request.QueryString["ID"].ToString());
if (!IsPostBack)
{
BindControlvalues();
}
}
private void BindControlvalues()
{
con = new SqlConnection(connString);
con.Open();
cmd = new SqlCommand("select * from Table_1 where ID=" + userid, con);
da = new SqlDataAdapter(cmd);
con.Close();
ds = new DataSet();
da.Fill(ds);
title.Text = ds.Tables[0].Rows[0][1].ToString(); //title
string date = Convert.ToString(ds.Tables[0].Rows[0][4]);
pub.Text = DateTime.Parse(date).ToString("yyyy-MM-dd"); //date
Editor1.Content = ds.Tables[0].Rows[0][6].ToString(); //content
}
Neodynamic
Participant
1150 Points
316 Posts
Re: Query String on image bytes
Oct 10, 2012 10:53 AM|LINK
I'm sorry but I still do not understand what you want to do at the end. Look, when a file is uploaded, you get that through the PostedFile property which is an object of type HttpPostedFile
That class features a couple of properties. One of them is FileName which is a the path (on the client machine) of the uploaded file. To get and work on the uploaded file at the server side (your ASP.NET app) you need to use the InputStream property.
colol
Member
117 Points
542 Posts
Re: Query String on image bytes
Oct 10, 2012 11:54 PM|LINK
What I am trying to do is display the path of the image, when edit is click, so that when the user doesnt change the image, it will still be displayed as the path is not change or the etxtbox is not empty
Neodynamic
Participant
1150 Points
316 Posts
Re: Query String on image bytes
Oct 11, 2012 10:36 AM|LINK
I think that based on all the messages above it's clear that with a posted file you have, #1 the path of the file (but on the client machine NOT on the server), and #2 the file binary content in the server's memory.