Validation before upload

May 22, 2010 at 2:16 PM

hi, i m trying to using this flajaxian file uploader. in my page, i have a dropdownlist to let the users select an album before upload the process. i have no idea to control the browse or upload button in the flajaxian. 

i just want to do some validation before the users can proceed the upload process.

anyone can give me some guidance? hope can hear from you all soon.

 

thank you

 

Mar 2, 2011 at 3:32 PM

I have the same question, kindly respond

Mar 22, 2011 at 10:05 AM

i face the same problem.

 

i have the coding below on html page:

<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="UploadFile.aspx.vb" Inherits="UploadFile" title="Upload FIle" %>
<%@ Register TagPrefix="fjx" Namespace="com.flajaxian" Assembly="com.flajaxian.FileUploader" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<script>
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+" isLast:"+isLast+"</br>";
    }
}
</script>

 <div id="MyDiv"></div>
 <fjx:FileUploader ID="FileUploader1" runat="server" RequestAsPostBack="true"  JsFunc_FileStateChanged="FileStateChanged" IsDebug="true" CssUrl="~/css/FileUploader.css" TransparentBackground="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>

</asp:Content>

 

Everything look ok and file is uploaded successful.

i want to talk to code behind and i am using VB.NET.

OnFileNameDetermining="FileNameDetermining", i can't called code behind.

If something wrong with code behind function or something wrong with the call function?

Below is my code behind:

 

Imports UploadFile
Imports System.IO
Imports com.flajaxian

Partial Class UploadFile
    Inherits System.Web.UI.Page


    Protected Sub FileNameDetermining(ByVal sender As Object, ByVal args As FileNameDeterminingEventArgs)
        Label1.Text = "123"
        If System.IO.File.Exists(Server.MapPath("~/UploadFolder/" & args.FileName)) Then
            'Response.Write("YES")
            'args.CancelProcessing = True
            ' or if you want to stop the upload call args.CancelProcessing = true;
            args.FileName = "123.jpg"
        Else
            args.FileName = "123.jpg"
            'Response.Write("No")
        End If
    End Sub
End Class

 

Mar 23, 2011 at 4:29 AM

Hi,

I able to validate the file before upload.

 <fjx:FileUploader ID="FileUploader1" runat="server" RequestAsPostBack="true"  JsFunc_FileStateChanged="FileStateChanged"  OnFileReceived="FileUploader_FileReceived"
 IsDebug="true" CssUrl="~/css/FileUploader.css" TransparentBackground="true">
 
</fjx:FileUploader>

 

Code Behind:

Protected Sub FileUploader_FileReceived(ByVal sender As Object, ByVal e As FileReceivedEventArgs) Handles FileUploader1.FileReceived


        If System.IO.File.Exists(Server.MapPath("~/UploadFolder/" & e.File.FileName)) Then
          
            'Don't UPload file.
        Else
          'Upload File
            e.File.SaveAs(Server.MapPath("UploadFolder" & "\" & e.File.FileName))
        End If
     
        If (Not ClientScript.IsStartupScriptRegistered("alert")) Then
            Page.ClientScript.RegisterStartupScript _
            (Me.GetType(), "alert", "alertMe();", True)
        End If
    End Sub

 

But i not able to Label to inform which file is uploaded and which is not uploaded.
I trying call javascript from code behind but not working.

With Code Below:

 If (Not ClientScript.IsStartupScriptRegistered("alert")) Then
            Page.ClientScript.RegisterStartupScript _
            (Me.GetType(), "alert", "alertMe();", True)
        End If