foreach on FileReceived

Mar 3, 2009 at 4:08 PM
Edited Mar 3, 2009 at 7:09 PM
Hi flajaxian, tanks for your great work. I'll want to save the uploaded files in severals folders. For to do this i think to use the FileUpoloader_fileReceived method but it's work only with the last file.

My method on codebehide is :
protected void FileUploader_FileReceived(Object sender, FileReceivedEventArgs e)
{
            
 string fileName = e.File.FileName;

 if (FileUploader1.FileIsPosted)
 {
                string myLocation1 = System.Configuration.ConfigurationManager.AppSettings["UploadFolder1"].ToString();
                string myLocation2 = System.Configuration.ConfigurationManager.AppSettings["UploadFolder2"].ToString();

                string extention = fileName.Substring(fileName.LastIndexOf('.'));

                StringComparison[] scValues =
                {
                    StringComparison.CurrentCulture,
                    StringComparison.CurrentCultureIgnoreCase,
                    StringComparison.InvariantCulture,
                    StringComparison.InvariantCultureIgnoreCase,
                    StringComparison.Ordinal,
                    StringComparison.OrdinalIgnoreCase
                };

                foreach (StringComparison sc in scValues)
                {
                    if (extention == ".jpg")
                    {    
                         e.File.SaveAs(myLocation1 + "\\" + fileName);
                    }
                    else if (extention == ".bmp")
                    {    
                         e.File.SaveAs(myLocation2 + "\\" + fileName);
                    }
                }
}

my .aspx is:

<%@ Page Language="C#" MasterPageFile="~/Shared/MasterPages/Site.master" CodeBehind="Update.aspx.cs" AutoEventWireup="true" Inherits="Namespace.Update" %>
<%@ Register TagPrefix="fjx" Namespace="com.flajaxian" Assembly="com.flajaxian.FileUploader" %>

<asp:Content ID="TitleContententUploadPage" runat="server" ContentPlaceHolderID="TitleContentPlaceHolder">
     <script language="javascript" type="text/javascript">
     function FileStateChanged(uploader, file, httpStatus, isLast) {
        Flajaxian.fileStateChanged(uploader, file, httpStatus, isLast);
        var t = Flajaxian.$("MyDiv");
        if (file.state > Flajaxian.File_Uploading) {
            t.innerHTML += "bytes:" + file.bytes + " name:" + file.name + " state:" + file.state + " httpStatus:" + httpStatus + "</br>";
        }
     }
     </script>
    <span>Upload Manager</span>
    <br />
</asp:Content>
<asp:Content ID="DescriptionContenentUploadPage" runat="server" ContentPlaceHolderID="DescriptionContentPlaceHolder">
    <span>This area is used to upload a set of file from the web. Choose the file type to
        upload.<br />
    </span>
</asp:Content>
<asp:Content ID="ContentPlaceHolder1" ContentPlaceHolderID="ContentPlaceHolder1"
    runat="Server" Visible="false">
    <br />
    <br />
    <div id="MyDiv"></div>
    <br />
    <fjx:FileUploader ID="FileUploader1" OnFileReceived="FileUploader_FileReceived" JsFunc_FileStateChanged="FileStateChanged" runat="server"  >
        <Adapters>
            <fjx:FileSaverAdapter runat="server" />
            <fjx:ThumbGeneratorAdapter runat="server" Extensions=".xls" MaximumHeight="200" MaximumWidth="200" />
        </Adapters>
    </fjx:FileUploader>
    <br />
    <br />  
    <br />
    <br />
</asp:Content>

is possible implement this process for every one file that i want upload?? I've noted that without windows authentication the code works fine..!
my web.config authentication settings for upload page is..

<authorization>
     <allow roles="Administrators" />
    <deny users="*" />
</authorization>

when i implement this, the code dosn't work fine..and the system want that i re-entered user credential for every files...so if i want upload 10 files the system want that i inser 10 times the credential...

Coordinator
Mar 6, 2009 at 12:43 PM
The control doesn't work with Window authentication. Here is another discussion on that: http://flajaxianfileupload.codeplex.com/Thread/View.aspx?ThreadId=38566