Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET C#4.0
i have ajaxfileupload control , i want to insert the image to the database ,
but i want to insert it throw button , not from the upload complete event ,
so i make the button but there isn't filename property !
any help ?
p.s i use the ajax control because i want to preview it first and it have a javascript code that preview the image
____
 
protected void fileUploader_UploadComplete(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"))
        {
            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);   
    }
 
and
protected void btnInsert_Click(object sender, EventArgs e)
    {
         
        //string filePath = "~/_Manage_/upimages/" + file.FileName;
        //fileUploader.SaveAs(filePath);
    }
Posted 28-Dec-12 12:35pm
Edited 28-Dec-12 15:12pm
v4
Comments
Sergey Alexandrovich Kryukov at 28-Dec-12 18:38pm
   
This is not a correct question. Who told you you need to do exactly that? You need to start with what you want to achieve really, forget about how for this moment...
—SA
Ahmad Abd-Elghany at 28-Dec-12 18:42pm
   
what !!!?
Sergey Alexandrovich Kryukov at 28-Dec-12 18:51pm
   
That! What part of my comment you did not understand?
Don't try to abuse event mechanism, adhere to it. Explain your ultimate goal; and I tell you how to reach it.
—SA
Ahmad Abd-Elghany at 28-Dec-12 18:57pm
   
i corrected my question :)
Zaf Khan at 28-Dec-12 21:08pm
   
Note:
I forgot to add.... to my solution...
The fileupload will let you upload to ANY location you say as long as it is WRITEABLE location... but you would upload it to a SECRET/NON-PUBLIC area as you dont want everyone to drop just any file in your important folders, so its best to nominate an uploads folder and empty it before/after uploads. off course if your server is busy then there may be several uploads happening at once! so then you cant empty it before/after but using a sequential numbering system helps keep track of the files and you can remove the temporary files once the user ok/cancels their uploaded file, and ALSO you would have the file path for preview once uploaded too.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I was always under the impression that the fileupload component alowed you to upload a file to a non publically accessible area like an _uploads/uploads folder for example and the file named to anything you wanted like upload243.doc and then once uploaded (and the file extension PRESERVED) and ONLY THEN the user is given the option to OK/Cancel via your button event.
 
And if the user OK then you already know the file name and location and you can chunk it into your DB as you like...
 
And if the user choose CANCEL then you can delete it from your servers NON PUBLIC space.
 
So dont neccessarily think about completing the action in one shot, even though it may be possible.... try to think of it as a two step manouvre.
 
where...
 
1- User chooses file and you UPLOAD to TEMPORARY location
2a- User choose OK and you process and then delete the temporary file
OR
2b- User choose CANCEL you delete the temporary file
  Permalink  
Comments
Ahmad Abd-Elghany at 28-Dec-12 21:12pm
   
i just use that control because it have a javascript code that preview the image after uploadcomplete event .
so i don't have to write more codes to make preview for the image before insert it into the database or to make a circle of upload it and preview it to an image and after that insert it .
Zaf Khan at 28-Dec-12 22:01pm
   
My javascript isnt too tough and neither is my ajax, but i'm sure if the upload event completes without errors then the file path and contents fo file (data) would be saved on the server somewhere most likely in your session object.

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



Advertise | Privacy | Mobile
Web04 | 2.8.140709.1 | Last Updated 28 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid