protected void AjaxFileUpload1_OnUploadComplete(object sender, AjaxFileUploadEventArgs file)
    {
        // User can save file to File System, database or in session state
        if (file.ContentType.Contains("jpg") || file.ContentType.Contains("gif") ||
            file.ContentType.Contains("png") || file.ContentType.Contains("jpeg"))
        {
            // Limit preview file for file equal or under 4MB only, otherwise when GetContents invoked
            // System.OutOfMemoryException will thrown if file is too big to be read.
            if (file.FileSize <= 1024 * 1024 * 4)
            {
                Session["fileContentType_" + file.FileId] = file.ContentType;
                Session["fileContents_" + file.FileId]    = file.GetContents();

                // Set PostedUrl to preview the uploaded file.
                file.PostedUrl = string.Format("?preview=1&fileId={0}", file.FileId);
            }
            else
            {
                file.PostedUrl = "fileTooBig.gif";
            }

            // Since we never call the SaveAs method(), we need to delete the temporary fileß
            file.DeleteTemporaryData();
        }

        // In a real app, you would call SaveAs() to save the uploaded file somewhere
        // AjaxFileUpload1.SaveAs(MapPath("~/App_Data/" + file.FileName), true);
    }
        protected void File_Upload(object sender, AjaxFileUploadEventArgs e)
        {
            string filename = e.FileName;
            int    userID   = 1;          // Foreign key to Table Users..
            int    albumID  = 10;         // Foreign key to Table Albums..
            string username = "******"; // USE Context.User.Identity.Name for authenticated users..

            try
            {
                // Resize image before upload | Create thumbnail for previews..
                Stream       fileStream = e.GetStreamContents();
                ImageResizer imRes      = new ImageResizer(307200, fileStream, Path.GetExtension(filename));
                byte[]       imageThumbnail;
                byte[]       scaledUploadFile = imRes.ScaleImageFromStream(out imageThumbnail, 200, 200);

                // Generate a Guid for public file name..
                Guid             guid       = Guid.NewGuid();
                AzurePhotoClient blobClient = new AzurePhotoClient("azurephotos");
                blobClient.UploadFromBytes(scaledUploadFile, "hq/" + username + "/album/" + albumID + "/" + guid + Path.GetExtension(filename));
                blobClient.UploadFromBytes(imageThumbnail, "thumbnail/" + username + "/album/" + albumID + "/" + guid + Path.GetExtension(filename));

                // Log photo to DB..
                DbAccess dbAccess = new DbAccess();
                dbAccess.InsertPhotoToDb(userID, filename, guid, scaledUploadFile.Length, albumID);

                e.DeleteTemporaryData();
            }
            catch (Exception ex)
            {
                // Log error..
            }
        }
        protected void AjaxFileUpload1_OnUploadComplete(object sender, AjaxFileUploadEventArgs file)
        {
            if (hidisvalid.Value == "")
            {
                string datetime     = DateTime.Now.ToFileTimeUtc().ToString();
                string filename     = "";
                string originalfile = "";
                if ((Convert.ToDouble(hidcurfilesize.Value) + file.FileSize) <= Convert.ToDouble(hidfilesize.Value) * 1024 * 1024)
                {
                    try
                    {
                        String extension = Path.GetExtension(file.FileName);
                        filename     = datetime + extension;
                        originalfile = file.FileName;
                        // Limit preview file for file equal or under 4MB only, otherwise when GetContents invoked
                        // System.OutOfMemoryException will thrown if file is too big to be read.
                        if (file.FileSize <= Convert.ToDouble(hidfilesize.Value) * 1024 * 1024)
                        {
                            Session["fileContentType_" + file.FileId] = file.ContentType;
                            Session["fileContents_" + file.FileId]    = file.GetContents();

                            // Set PostedUrl to preview the uploaded file.
                            // file.PostedUrl = string.Format("?preview=1&fileId={0}", file.FileId);
                            file.PostedUrl = "downloads.png";
                        }
                        else
                        {
                            file.PostedUrl = "downloads.png";
                        }

                        hidcurfilesize.Value = (Convert.ToDouble(hidcurfilesize.Value) + file.FileSize).ToString();
                        string directory = @"webfile/emailfile/";
                        // Since we never call the SaveAs method(), we need to delete the temporary fileß
                        string dir = Server.MapPath(directory);
                        if (!Directory.Exists(Server.MapPath(directory)))
                        {
                            Directory.CreateDirectory(Server.MapPath(directory));
                        }
                        AjaxFileUpload1.SaveAs(MapPath(directory + filename), true);

                        if (Session["file"] == null)
                        {
                            tblfile = createtable();
                        }
                        else
                        {
                            tblfile = (DataTable)Session["file"];
                        }

                        itemdr = tblfile.NewRow();



                        itemdr["originalname"] = originalfile;

                        itemdr["savename"] = filename;
                        itemdr["ext"]      = extension;
                        tblfile.Rows.Add(itemdr);

                        Session["file"] = tblfile;

                        file.DeleteTemporaryData();
                    }
                    catch
                    {
                    }
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "temp", "<script type='text/javascript'> alert('File exceeds upload size limit');</script>", false);
                }

                //}
                //else
                //{
                //    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "temp", "<script type='text/javascript'> alert('The Files you are trying to send exceed the Max Limit.');</script>", false);

                //}
            }
        }
        protected void AjaxFileUpload1_OnUploadComplete(object sender, AjaxFileUploadEventArgs file)
        {
            string datetime     = DateTime.Now.ToFileTimeUtc().ToString();
            string filename     = "";
            string originalfile = "";

            try
            {
                String extension = Path.GetExtension(file.FileName);
                filename     = Session["userid"].ToString() + "_" + datetime + extension;
                originalfile = file.FileName;
                // Limit preview file for file equal or under 4MB only, otherwise when GetContents invoked
                // System.OutOfMemoryException will thrown if file is too big to be read.
                if (file.FileSize <= 1024 * 1024 * 50)
                {
                    Session["fileContentType_" + file.FileId] = file.ContentType;
                    Session["fileContents_" + file.FileId]    = file.GetContents();

                    // Set PostedUrl to preview the uploaded file.
                    // file.PostedUrl = string.Format("?preview=1&fileId={0}", file.FileId);
                    file.PostedUrl = "downloads.png";
                }
                else
                {
                    file.PostedUrl = "downloads.png";
                }


                string directory = @"webfile/" + Session["companyid"].ToString() + "/";
                // Since we never call the SaveAs method(), we need to delete the temporary fileß
                string dir = Server.MapPath(directory);
                if (!Directory.Exists(Server.MapPath(directory)))
                {
                    Directory.CreateDirectory(Server.MapPath(directory));
                }
                AjaxFileUpload1.SaveAs(MapPath(directory + filename), true);

                if (Session["file"] == null)
                {
                    tblfile = createtable();
                }
                else
                {
                    tblfile = (DataTable)Session["file"];
                }

                itemdr = tblfile.NewRow();



                itemdr["originalname"] = originalfile;

                itemdr["savename"] = filename;
                itemdr["ext"]      = extension;
                tblfile.Rows.Add(itemdr);

                Session["file"] = tblfile;

                file.DeleteTemporaryData();
            }
            catch
            {
            }
        }