473,405 Members | 2,415 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

How to use Ajax for FileUpload?

28
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:

Expand|Select|Wrap|Line Numbers
  1. private void cmdUpload_Click(object sender, System.EventArgs e)
  2.         {
  3.             if (FileInput.PostedFile.FileName == "") 
  4.             {
  5.                 lblInfo.Text = "No file specified.";
  6.             } 
  7.             else 
  8.             {
  9.                 try 
  10.                 {
  11.                     if (FileInput.PostedFile.ContentLength > 1048576) 
  12.                     {
  13.                         lblInfo.Text = "File is too large.";
  14.                     }
  15.                     else 
  16.                     {
  17.                         string fileName = Path.GetFileName(FileInput.PostedFile.FileName);
  18.                         string filepath = Server.MapPath("") +"\\bin\\CustomerPic\\"+fileName;
  19.                         FileInput.PostedFile.SaveAs(filepath);
  20.                         lblInfo.Text = "File " + fileName + " uploaded.";
  21.                     }
  22.                 }
  23.                 catch (Exception err) 
  24.                 {
  25.                     lblInfo.Text = err.Message;
  26.                 }
  27.             }
  28.         }
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.PostFile in code behind.
Or you can tell me other way to use ajax for FileUpload.
I hope to have true answer than other.
Thanks.
Jan 10 '08 #1
0 1178

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Christian Schlemmer | last post by:
If my code will run into the filesize-limit condition, the INSERT-statement will be executed. is there a way to avoid that? Protected Sub DetailsView1_RowInserting(ByVal sender As Object,...
1
by: kmithu | last post by:
Hi friends, I want to upload a file on AJAX web page. The HTML code i m using is: ---------------------------------------------------------------------------------------- <asp:ScriptManager...
3
by: kmithu | last post by:
Hi friends, I want to upload a file on AJAX web page. The HTML code i m using is: ---------------------------------------------------------------------------------------- <asp:ScriptManager...
2
by: Kevin | last post by:
Hi! how can I upload a file with ajax? Because when I submit my form the postedfile is null. THanks
2
by: Bjorn Sagbakken | last post by:
I was looking for a solution, without the full page postback, and all the tip was about a hidden iframe and RJS. The RJS was not known to me before, and still I haven't explored this used with...
1
by: Code Monkey | last post by:
I've got a FileUpload control placed on a web page. The control is embedded inside an UpdatePanel. It uploads the file OK, but.... Load the page, click on a button to show the upload panel....
9
by: vital | last post by:
Hi, I have a User control which has a fileupload control. With the requirements I placed the user control in a UpdatePanel of ASP.NET Ajax and the fileupload.postedfile.filename giving error. ...
4
by: pechar | last post by:
Hi All, This question has been asked many times and I've checked most of the sites with resolutions. None worked for me. 1) I have a page which is a content page to a Masterpage . 2) I have a...
3
by: Fresno Bob | last post by:
I know this has been addressed sortof. It's using the update panel with the fileupload control. I get how to use a postback trigger to do a full postbask. However my page has some server side...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.