Click here to Skip to main content
Rate this: bad
good
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 3:42am

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

  Print Answers RSS
0 OriginalGriff 245
1 Jochen Arndt 155
2 PIEBALDconsult 150
3 Afzaal Ahmad Zeeshan 120
4 DamithSL 115
0 OriginalGriff 5,695
1 DamithSL 4,591
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 29 Dec 2012
Copyright © CodeProject, 1999-2014
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