Get Names of Posted File

Apr 2, 2011 at 6:32 AM

<fjx:FileUploader ID="FileUploader1" runat="server" RequestAsPostBack="true">
            <Adapters>
                <fjx:FileSaverAdapter Runat="server" FolderName="images" />
                <fjxau:AmazonUploader AccessKey="WebConfig:AmazonAccessKey" SecretKey="WebConfig:AmazonSecretKey"
                    BucketName="media.flajaxian.com">
                    <AccessControlList>
                        <fjxau:AccessControl URI="http://acs.amazonaws.com/groups/global/AllUsers" Permission="READ" />
                        <fjxau:AccessControl EmailAddress="john@flajaxian.com" Permission="FULL_CONTROL" />
                    </AccessControlList>
                </fjxau:AmazonUploader>
            </Adapters>
        </fjx:FileUploader>

 

I am using This Code to Store Images on local Directory

but I Want to get All Posted File Collection to Store names of Files in Database.. I mean to store Path of the Posted File in Database..

How to Do it ..?

 

And Excellent Control Cheers..!!!

May 21, 2011 at 9:35 AM

handle the event OnFileReceived

<fjx:FileUploader ID="FileUploader1" runat="server" OnFileReceived="OnFileReceived" >

	<Adapters>

		<fjx:FileSaverAdapter FolderName="..\\images\\"></fjx:FileSaverAdapter>

	</Adapters>

</fjx:FileUploader>

you need to handle it like this:

protected void OnFileReceived(object sender, com.flajaxian.FileReceivedEventArgs e) {
	//do what you want with the e.File.FileName
}

Sep 8, 2011 at 6:41 PM
Edited Sep 8, 2011 at 6:42 PM

First this is a fantastic control.  Big kudos to the author.  

The above code worked for me very well.  I just wrote an object that does the IO to the database and file system simultaneously.  

 

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>

            <fjx:FileUploader ID="FileUploader1" runat="server" OnFileReceived="fileUploader_FileReceived">
                <Adapters>
                    <fjx:FileSaverAdapter FolderName="Folder1"></fjx:FileSaverAdapter>
                </Adapters>
            </fjx:FileUploader>

        </ContentTemplate>
    </asp:UpdatePanel>

 

Code Behind: 

 

        protected void fileUploader_FileReceived(object sender, com.flajaxian.FileReceivedEventArgs e)
        {
            Model.PhyleLogic myPhyleLogic = new Model.PhyleLogic();
           
            int imgLength = e.File.ContentLength;
            string sExtension = System.IO.Path.GetExtension(e.File.FileName).ToLower();

            // Create a byte to hold the data and give it the length
            byte[] imgBinaryData = new byte[imgLength];
            e.File.InputStream.Read(imgBinaryData, 0, imgLength); // Read it into a stream (int)

            myPhyleLogic.FileName = e.File.FileName.ToLower();
            myPhyleLogic.FileContentType = "application/" + sExtension;
            myPhyleLogic.FileContent = imgBinaryData;

            int newFileId = myPhyleLogic.Insert();// new record ID number

        }

 

PhyleLogic is the name of the class I created for the database interaction.  Sounded like fun on a Thursday :p

Data Table has only four columns; FileId, FileName, FileContentType, FileContent  Pretty simple.  

I hope this helps.