at first put the fili upload control then write the above code:
dim s as string
s=server.mappath("image")+fileupload1.filename
fileupload1.saveas(s)
image1.imageurl=s
the above code help you
Can some one tell me how to upload the iamge int the webpage and the show it in datagrid view and also 2 images in one row.?
at first put the fili upload control then write the above code:
dim s as string
s=server.mappath("image")+fileupload1.filename
fileupload1.saveas(s)
image1.imageurl=s
the above code help you
this is a trditional way that all have posted but we can also use the image data type in the db server. It accepts byte value of the image. This can be used with javascript on the client side to read the byte values and then passing into the page control to the database.
This code will help you:
private void Button1_Click(object sender, System.EventArgs e)
{
//It verifies if the archive exists
if (Upload.PostedFile != null)
{
//To create a PostedFile
HttpPostedFile File = Upload.PostedFile;
//Create byte Array with file len
byte[] Data = new Byte[File.ContentLength];
//force the control to load data in array
File.InputStream.Read(Data,0,File.ContentLength);
int i = 0;
//Dysplay array data in textbox
for (i=0;i<Data.Length;i++)
{
TextBox1.Text += Data[i].ToString();
}
//Create procedure parameter
object[] obj = new object[1];
obj[0] = Data;
//Execute the procedure with Microsoft.ApplicationBlocks.Data
//Simple procedure
/*CREATE PROCEDURE sp_img(@img image) AS
insert into tb_img values(@img)*/
//record data
SqlHelper.ExecuteNonQuery(connectionString,"sp_img ",obj);
}
}
private void Button2_Click(object sender, System.EventArgs e)
{
//Bind data to your grid
//more details consulting
//Working DataGrid TemplateColumns and Bind this Columns
DataSet ds = SqlHelper.ExecuteDataset(connectionString,
"sp_load_img",null);
grid.DataSource = ds.Tables[0].DefaultView;
grid.ObjectName = "Image1";
grid.FieldName = "img";
grid.Editable = false;
grid.DataBind();
grid.DataBindObjects(grid,ds,0,grid.PageSize);
int i =0;
for (i=0;i<ds.Tables[0].Rows.Count;i++)
{
//test your bitmap is valid
//Demonstration
byte[] bits = (byte[]) ds.Tables[0].Rows[i]
["img"];
MemoryStream memorybits = new MemoryStream(bits);
Bitmap bitmap = new Bitmap(memorybits);
}
}
private void grid_PageIndexChanged(object source,
System.Web.UI.WebControls.DataGridPageChangedEvent Args e)
{
//Page your grid
//Bind data to your grid
//more details consulting
//Working DataGrid TemplateColumns and Bind this Columns
grid.CurrentPageIndex =e.NewPageIndex;
DataSet ds = SqlHelper.ExecuteDataset(connectionString,
"sp_load_img",null);
grid.DataSource = ds.Tables[0].DefaultView;
grid.ObjectName = "Image1";
grid.FieldName = "img";
grid.Editable = false;
grid.DataBind();
grid.DataBindObjects(grid,ds,e.NewPageIndex,grid.P ageSize);
}
}
I know how to upload.
File Upload control is given to upload file.
You can use it and filter out for image and make a folder IMAGE in your project give it as a path for storing image.
For uploading image you can use
Fileupload1.postedfile.saveas(Server.Mappath(".\\i mages\\"+filename) to save the file
where fileupload1 is the component name of file field
I think so do not know whether the correct.
Use file upload control and save the images to the folder in your website
eg
if (fileImage.HasFile)
{
if (fileImage.PostedFile.ContentLength < 1048576)
{
String str = Guid.NewGuid().ToString();
string a = str;
str = Server.MapPath("~/Images/ImageGallery/") + str;
fileImage.SaveAs(str + ".jpg");
BllSodhis.Utility.GenerateThumb(str + "_Thumb.jpg", str + ".jpg", 100, 150);
_objProperty.ImagePath = a;
}
}
here fileImage is file upload control
There are currently 1 users browsing this thread. (0 members and 1 guests)
|
||||
Bookmarks