How can i retreive the filename of the image uploaded

Dec 31, 2008 at 4:42 AM

Hi,

I would like to know how to retreive the filename of the image and send it to the server.

Here is my code so far

 <fjx:FileUploader ID="FileUploader1" runat="server" MaxNumberFiles="10" RequestAsPostBack="True">
    <Adapters>
        <fjx:FileSaverAdapter Runat="server" FolderName="UploadFolder" />
        <fjx:ThumbGeneratorAdapter Runat="server"
            Extensions="jpg;jpeg" FolderName="UploadFolder"
            Suffix="_thumb" MaximumWidth="200" MaximumHeight="200" />
    </Adapters>

</fjx:FileUploader>

I'm guessing I shoud use... OnFileReceived attributes.

any help would be appreciated.

Thank...

JayPee





Coordinator
Dec 31, 2008 at 6:11 AM
Edited Dec 31, 2008 at 6:24 AM
There are many ways, you can use OnFileReceived or you can use 
<script runat="server">
protected void FileNameDetermining(object sender, FileNameDeterminingEventArgs args)
{
    // you can change  the name here by setting args.FileName = "NewName.jpeg" or just read it from there
}
</script>

<fjx:FileUploader ID="FileUploader1" runat="server">
    <Adapters>
        <fjx:FileSaverAdapter Runat="server" FolderName="UploadFolder" OnFileNameDetermining="FileNameDetermining" />
        <fjx:ThumbGeneratorAdapter Runat="server" MaximumWidth="200" MaximumHeight="200" />
    </Adapters>
</fjx:FileUploader>
Jan 3, 2009 at 1:51 AM
Hi Flajaxian,

Thanx for your reply..... it's working perfectly now.

Here's how I retreive the fileName and saved it to my database using a TableAdapter.

Once again.... thank you so much.

Jp



<script runat="server">
    
protected void FileNameDetermining(object sender, FileNameDeterminingEventArgs args)

        {
 
            DateTime date1 = DateTime.Now;
            args.FileName = "picture" + tt + ".jpg";
     
            tt++;
          DataSet2TableAdapters.Photo33TableAdapter caroAdapter = new DataSet2TableAdapters.Photo33TableAdapter();
          caroAdapter.InsertPhoto33(11114, "title", "Description", args.FileName, date1, tt);

        }

</script>
   
<div id="MyDiv"></div>
<fjx:FileUploader ID="FileUploader1" runat="server" RequestAsPostBack="True">
    <Adapters>
        <fjx:FileSaverAdapter Runat="server" FolderName="UploadFolder" OnFileNameDetermining="FileNameDetermining"/>
        <fjx:ThumbGeneratorAdapter Runat="server" Extensions="jpg;jpeg" FolderName="UploadFolder" Suffix="_thumb" MaximumWidth="200" MaximumHeight="200" />
    </Adapters>
</fjx:FileUploader>
Jan 3, 2009 at 9:02 AM
Hi again...

I'm having trouble incrementing my variable in my function.

 i want to have each picture with a unique name like :... picture 1.jpg... picture2.jpg....

Any toughts?
Coordinator
Jan 4, 2009 at 6:51 AM
Edited Jan 4, 2009 at 6:52 AM
Well one thing you can do is increment a static variable like this:

<script runat="server">

private static int _pictureIndex = 0;
protected void FileNameDetermining(object sender, FileNameDeterminingEventArgs args) { string name = "image"+(_pictureIndex++)+".jpeg"; }
</script> <fjx:FileUploader ID="FileUploader1" runat="server"> <Adapters> <fjx:FileSaverAdapter Runat="server" FolderName="UploadFolder" OnFileNameDetermining="FileNameDetermining" /> <fjx:ThumbGeneratorAdapter Runat="server" MaximumWidth="200" MaximumHeight="200" /> </Adapters> </fjx:FileUploader>
But if you reboot your server the numbers will start back from 0 so you will end up with collisions, so I would suggest to rather use Guids like this:

<script runat="server">

protected void FileNameDetermining(object sender, FileNameDeterminingEventArgs args) { string name = Guid.NewGuid()+".jpeg"; }
</script> <fjx:FileUploader ID="FileUploader1" runat="server"> <Adapters> <fjx:FileSaverAdapter Runat="server" FolderName="UploadFolder" OnFileNameDetermining="FileNameDetermining" /> <fjx:ThumbGeneratorAdapter Runat="server" MaximumWidth="200" MaximumHeight="200" /> </Adapters> </fjx:FileUploader>

Jan 7, 2009 at 5:13 PM
Edited Jan 7, 2009 at 5:18 PM
Hi,

How to have this event "OnFileNameDeternining" when I'm using a CustomAdapter ?

This is my problem:
I want to upload a file by an asynchrone query with a UpdatePanel. And I want renamed the uploaded file too.

so to rename file, I expose the event "ProcessFile" so I make a custom adapter:

CustomAdapter.cs
using System;
using System.Collections.Generic;
using System.Text;
using com.flajaxian;
using System.Web;

namespace Inpact.ToolsAndComponents.Components.FileUpload {
    public class CustomAdapter : FileUploaderAdapter {

        public event ProcessFileEventHandler ProcessFileEvent;
        public delegate void ProcessFileEventHandler(HttpPostedFile file);

        /// <param name="file">Incoming file</param>
        public override void ProcessFile(HttpPostedFile file) {
            if (ProcessFileEvent != null)
                ProcessFileEvent.Invoke(file);
        }   
    }
}

and I have an aspx page to use your (excellent ;) ) control with my customAdapter
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<%@ Register Assembly="Inpact.ToolsAndComponents" Namespace="Inpact.ToolsAndComponents.Components.FileUpload" TagPrefix="IN" %>
<%@ Register Assembly="com.flajaxian.FileUploader" Namespace="com.flajaxian" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
    <form id="form1" runat="server">
          
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <cc1:FileUploader ID="FileUploader1" runat="server" UseInsideUpdatePanel="true">
                <adapters>
                <IN:CustomAdapter Runat="server" />
                </adapters>
            </cc1:FileUploader>
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
        </ContentTemplate>
    </asp:UpdatePanel>
</body>
</html>

and this aspx page's code behind:
 protected void Page_Load(object sender, EventArgs e) {
        ((Inpact.ToolsAndComponents.Components.FileUpload.CustomAdapter)FileUploader1.Adapters[0]).ProcessFileEvent
 += new Inpact.ToolsAndComponents.Components.FileUpload.CustomAdapter.ProcessFileEventHandler(Default2_ProcessFileEvent);

    }

void Default2_ProcessFileEvent(HttpPostedFile file) {
        Random r = new Random();
        string sFileName = file.FileName;
        string extention = sFileName.Substring(sFileName.LastIndexOf('.'));
        sFileName = sFileName.Substring(0, sFileName.LastIndexOf('.'));
        sFileName = sFileName + r.Next(0, 99).ToString() + extention;
        file.SaveAs(Path.Combine(Server.MapPath("~/Upload/Utilisateurs/avatars"), sFileName));
        Label1.Text =sFileName;//display new name
        UpdatePanel1.UpdateMode= UpdatePanelUpdateMode.Conditional;
        UpdatePanel1.Update();
    }
So when I upload a file, "Default2_ProcessFileEvent" fires and the uploaded file is renamed and saved on the hard disk.
But after I want display the new name of this file in the label. But this event doesn't fire the updatePanel refresh.
Yet I use "UseInsideUpdatePanel".

so for help me:
-> how to use the event "OnFileNamedetermining" to return the new name by the property "ChangedName" but the class "FileUploaderAdapter" doesn't have this method.
or
-> how to update my updatePanel ?

thanks :)

gBen
Jan 14, 2009 at 2:45 PM
Hi,
Have you found a solution to updating the update panel? If so, could you please share it?

Thanks
Jan 14, 2009 at 2:54 PM
No sorry,
Nobody answered me.
And I didn't find a solution.
So I use another uploadfile control.

sorry

bye
Jan 14, 2009 at 2:56 PM
Thanks for the quick reply...would you mind sharing what control you use?
Jan 14, 2009 at 3:02 PM
Yep of course !
I use this
http://en.fileuploadajax.subgurim.net/

It uses an iframe to make a "asynchronous" request.





Jan 14, 2009 at 9:05 PM
Hey Thanks for all your replies. I was looking at that control. Will it be possible for you to send me some sample of how you implemented it? I would really appreciate it. m_rathi@hotmail.com

Thanks
Jun 1, 2009 at 7:25 PM

hi

can you use progress bar with this upload control ?

and can u show ur pictures at picturebox ?

if u can do this, can u help me and send me a sample ?

Thanks