Click here to Skip to main content
12,955,891 members (65,268 online)
Rate this:
 
Please Sign up or sign in to vote.
hi , i have an AjaxFileUpload control for uploading images ,
and i made a java script code to display the image after
AjaxFileUpload_UploadComplete event ,
so i try it i just upload it into a session and display it .

now , i want to insrt it into a database from another button
not from the UploadComplete Event .

how can i do that ?


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AjaxControlToolkit;
using System.IO;
 
public partial class _Manage__ProductsEdit : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["preview"] == "1" && !string.IsNullOrEmpty(Request.QueryString["fileId"]))
        {
            var fileId = Request.QueryString["fileId"];
            var fileContents = (byte[])Session["fileContents_" + fileId];
            var fileContentType = (string)Session["fileContentType_" + fileId];
 
            if (fileContents != null)
            {
                Response.Clear();
                Response.ContentType = fileContentType;
                Response.BinaryWrite(fileContents);
                Response.End();
            }
 
        }
 

    }
 
    public  void fileUploader_UploadComplete(object sender, AjaxFileUploadEventArgs file)
    {
 
        string filePath = MapPath("~/_Manage_/upimages/") + Path.GetFileName(file.FileName);
        fileUploader.SaveAs(filePath);
        // 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"))
        {
            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);
    }
 
    // button to insert into data base
    protected void btnInsert_Click(object sender, ImageClickEventArgs e)
    {
    }
}
Posted 29-Dec-12 2:42am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,719
CHill60 3,550
Maciej Los 3,153
ppolymorphe 2,060
Jochen Arndt 1,975


Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 29 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100