public partial class ImageUploader : System.Web.UI.UserControl
{
#region
Variables
private string _uploadFolder = "~/Upload/Temp";
private string _imageHandler = "";
#endregion
#region
Constructor & destructor
#endregion
#region
Properties
/// <summary>
/// Gets or sets the upload folder
/// </summary>
public string UploadFolder
{
get
{
return _uploadFolder;
}
set
{
_uploadFolder =
value;
}
}
/// <summary>
/// Gets or sets the image handler url
/// </summary>
public string ImageHandler
{
get
{
return _imageHandler;
}
set
{
_imageHandler =
value;
}
}
#endregion
#region
Methods
protected void Page_Load(object sender, EventArgs e)
{
// Set values
imageUploader.TempDirectory = _uploadFolder;
}
protected void imageUploader_FileUploaded(object sender, UploaderEventArgs args)
{
try
{
using (Stream stream = args.OpenStream())
{
System.Drawing.
Bitmap img = new System.Drawing.Bitmap(stream);
img.Save(args.GetTempFilePath(), System.Drawing.Imaging.
ImageFormat.Png);
}
}
catch (Exception ex)
{
args.Delete();
}
}
protected void imageUploader_FileChanged(object sender, PersistedFileEventArgs args)
{
previewImage.ImageUrl =
string.Format("{0}?id={1}", _imageHandler, args.FileGuid);
}
#endregion
}