How to use Ajax for FileUpload?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thupham
    New Member
    • Oct 2007
    • 28

    How to use Ajax for FileUpload?

    I use Visual Studio 2003, and Ajax.dll
    In design, I have :
    1 FileField, named: FileInput, set runnat="server"
    1 Button (of Html toolbox), named: cmdUpload
    1 Label (of HTML toolbox), named: lblInfo
    First I create function for customer upload their file to server on click event:

    [CODE=cpp]private void cmdUpload_Click (object sender, System.EventArg s e)
    {
    if (FileInput.Post edFile.FileName == "")
    {
    lblInfo.Text = "No file specified.";
    }
    else
    {
    try
    {
    if (FileInput.Post edFile.ContentL ength > 1048576)
    {
    lblInfo.Text = "File is too large.";
    }
    else
    {
    string fileName = Path.GetFileNam e(FileInput.Pos tedFile.FileNam e);
    string filepath = Server.MapPath( "") +"\\bin\\Custom erPic\\"+fileNa me;
    FileInput.Poste dFile.SaveAs(fi lepath);
    lblInfo.Text = "File " + fileName + " uploaded.";
    }
    }
    catch (Exception err)
    {
    lblInfo.Text = err.Message;
    }
    }
    }[/CODE]
    This function is successful, then I want to use Ajax when Customer click on cmdUpload, I don't set FileInput runnat="server" , so code behind can't see FileInput.
    Can you give value of FileInput.PostF ile in code behind.
    Or you can tell me other way to use ajax for FileUpload.
    I hope to have true answer than other.
    Thanks.
    Last edited by Shashi Sadasivan; Jan 10 '08, 02:46 AM. Reason: adding code tags
Working...