Sample Page I like to share

Feb 7, 2009 at 11:23 AM
Edited Feb 7, 2009 at 11:25 AM
I have seen a few things here that I was have problems with and used some code that other user here have tried to use or sent here.
I have put together a sample page that may be of some use to others. This is coded in VB since I use vb.


<%@ Page Language="VB" Title="File Uploader Sample" %>
<%@ Import Namespace="System.IO" %>
<%@ Register Assembly="com.flajaxian.FileUploader" Namespace="com.flajaxian" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<script type="text/jscript">
function FileStateChanged(uploader, file, httpStatus, isLast){
    Flajaxian.fileStateChanged(uploader, file, httpStatus, isLast);
           document.location.href = document.location.href;
<script runat="server">
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    End Sub
    Protected Sub CreateFolders()
        'this will create folder that are need for this page
        'upload and a sub folder thumbs
        'The folders are related to where the page file is

        'Create the Upload directory if it does not exist.
        Dim strUploadFolder As String
        Dim myUploadpath As String = Server.MapPath(".")
        strUploadFolder = myUploadpath + "/Upload/"
        If (Not Directory.Exists(strUploadFolder)) Then
        End If

        'Create the thumbs directory if it does not exist.
        Dim strthumbsFolder As String
        Dim mythumbspath As String = Server.MapPath(".")
        strthumbsFolder = mythumbspath + "/Upload/thumbs/"
        If (Not Directory.Exists(strthumbsFolder)) Then
        End If
    End Sub
    Protected Sub Repeater1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim DI As New System.IO.DirectoryInfo(Server.MapPath("./Upload/thumbs"))
        Dim DT As New System.Data.DataTable()
        Dim DR As System.Data.DataRow
        For Each FI As System.IO.FileInfo In DI.GetFiles
            DR = DT.NewRow
            DR("FileName") = "Upload/thumbs/" & FI.Name
        Repeater1.DataSource = DT
        DT = Nothing
        DR = Nothing
        DI = Nothing
    End Sub

    Protected Sub FileUploader1_FileReceived(ByVal sender As Object, ByVal e As com.flajaxian.FileReceivedEventArgs)
    End Sub


<html xmlns="">
<head runat="server">
    <title>Untitled Page</title>
<body style="background-color:silver">
    <form id="form1" runat="server">
    <h2>File Uploader</h2>
<p>This will let users upload files to server and create thumbnails of the orginal file.
<br />Size Limit is 100KB for each image.
<br />Once the files have been uploaded, you will see the thumbnail of the orginal image.
<br />Click on the image to open the thumbnail image
<br />This will also create folder Upload and the sub folder Thumbs (the thumbnail images will be stored there).
<br />and the images will be placed there.</p>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <asp:Repeater ID="Repeater1" runat="server" OnLoad="Repeater1_Load">
                        <a href=' <%# Eval("FileName") %>' target="_blank"><img alt=' <%# Eval("FileName") %>' border="0" src=' <%# Eval("FileName") %>' style="border: thin solid #000000; margin: 5px"></a>
                <br />
                <cc1:FileUploader ID="FileUploader1" runat="server"
                    AllowedFileTypes="Web Images (Jpeg, Gif, Png):*.jpg;*.jpeg;*.png;*.gif"                   
                    MaxFileNumberReachedMessage="Maxium file that can be sent is {0}"
                    MaxFileSizeReachedMessage="No files bigger than {0} are allowed"
                        <cc1:FileSaverAdapter FolderName="Upload" />
                        <cc1:ThumbGeneratorAdapter FolderName="upload/thumbs" MaximumHeight="100" MaximumWidth="100" Suffix="_s" />


I hope this helps
Feb 7, 2009 at 7:35 PM
This is certainly a big help!  Question for you though, I'm not sure if you've run into it or not but I'm working with a querystring to determine what folder I should put the files in.  I'm also giving the files custom names.  I've noticed though that when the uploader is posting the files, it seems to clear the querystrings I'm using to set these folders.  Have you had any experience with this?

Feb 8, 2009 at 12:24 AM
Guys, you don't read the help file.

If you want to pass variables with the request use State container as shown here:

Feb 8, 2009 at 4:26 AM
Hi, I did read the help file... I guess its not laymen for me. But looking here and  trial and error, I seem to get it done. Not to say this isn't a great thing you have here. I mostly code in VB and most of the code here is CS. Have to try to convert it. That is why I place this sample page here so others can pick it apart and add things to it.

I see others asking questions about this  and they are mostly sent to the help file, but I think if there was usage examples it may get the point across.

Like I have said before... this is a great package and love to learn more on how to use it with databases (Access and SQL).

Feb 8, 2009 at 6:45 AM
Edited Feb 8, 2009 at 6:45 AM

Well in the help file almost all is markup and JavaScript so the C# shouldn't be a big issue there. Pretty much just remove the semicolon at the end. 

But I really appreciate that you want to share with others your code. We can possibly think something about submitting codesnippets including in VB I think, if that helps…

Feb 8, 2009 at 7:01 AM
Edited Feb 8, 2009 at 7:05 AM
I have created a google group where everyone could post a code snippet. Let's see if the idea takes off we can add a link to that on the main page.
Feb 8, 2009 at 7:17 AM
That would be a great idea, I will post anything I have here. I hope this takes off and other users will share too.

Thanks flajaxian