Yes, there are no client side solution for image upload. Hence one can do it by calling the server side handler and do all the processes with handler.
I used handler in my code and used one of "Uploadify" named Control.
I also used two ".js" and one flash files which i have downloaded through
http://www.uploadify.com/download/
<script src="Scripts/jquery.uploadify.v2.1.4.js" type="text/javascript"></script>
<script src="Scripts/swfobject.js" type="text/javascript"></script>
And after include above two files and one uploadify.swf call the uploadfiy function.
See the following code.
$(document).ready(function () {
$("#upImage").uploadify({
'uploader': 'uploadify.swf',
'cancelImg': './Images/cancel.png',
'buttonText': 'Select Image',
'script': 'Upload.ashx',
'folder': '/Images',
'fileDesc': 'Image Files',
'fileExt': '*.jpg;*.jpeg;*.gif;*.png',
'multi': false,
'auto': true,
'onComplete': function (event, ID, fileObj, response) {
rootPath = fileObj.name;
}
});
}
);
I have taken html input file control named "upImage" by using this control, i have called the handler "Upload.ashx".
This is my handler code
<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
public class Handler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
if (context.Request.Files.Count > 0)
{
string path = context.Server.MapPath("Images/DealsImage");
if (!System.IO.Directory.Exists(path))
System.IO.Directory.CreateDirectory(path);
var file = context.Request.Files[0];
string fileName;
if (HttpContext.Current.Request.Browser.Browser.ToUpper() == "IE")
{
string[] files = file.FileName.Split(new char[] { '\\' });
fileName = files[files.Length - 1];
}
else
{
fileName = file.FileName;
}
string strFileName = fileName;
fileName = System.IO.Path.Combine(path, fileName);
file.SaveAs(fileName);
string msg = "{";
msg += string.Format("error:'{0}',\n", string.Empty);
msg += string.Format("msg:'{0}'\n", strFileName);
msg += "}";
context.Response.Write(msg);
}
}
public bool IsReusable
{
get
{
return false;
}
}
}