|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
public partial class UploadImages : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnUploadImage_Click(object sender, EventArgs e)
{
//server side checking
if (FileUpload1.PostedFile.ContentType.ToLower().StartsWith("image") && FileUpload1.HasFile)
{
Hashtable imageHash = new Hashtable();
imageHash.Add("@imageData", FileUpload1.FileBytes);
DataBaseHelper DBHelper = new DataBaseHelper();
//storing image in to DataBase
DBHelper.ExecuteNonQuery("UploadImage", imageHash);
}
}
protected void btnUploadToFolder_Click(object sender, EventArgs e)
{
//save file in folder
if (FileUpload1.PostedFile.ContentType.ToLower().StartsWith("image") && FileUpload1.HasFile)
{
string savelocation = Server.MapPath("savedImages/");
string fileExtention = System.IO.Path.GetExtension(FileUpload1.FileName);
//creating filename to avoid file name conflicts.
string fileName = Guid.NewGuid().ToString();
//saving file in savedImage folder.
string savePath = savelocation + fileName + fileExtention;
FileUpload1.SaveAs(savePath);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.