views:

384

answers:

2

I have a webform that has an ASP file upload object and I want to use jQuery to grab the file they have selected and upload the file via AJAX.

However I am having problems grabbing the file name after it's been selected.

Here is the HTML/ASP Code:

 <asp:FileUpload runat="server" ID="NewPic" />
   <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="NewPic" runat="server" Display="Dynamic" Text="You need to pick a picture." CssClass="mandatory"></asp:RequiredFieldValidator>

This is what I have tried but doesn't seem to work

uploadText = $('input[type=file]').value;
alert('FileName: ' + uploadText);
+1  A: 

Give this a try:

uploadText = $(':file').val();
alert('FileName: ' + uploadText);
womp
Do you know how to select the full file path?As in C:\Docs\pic1.jpginstead of justpic1.jpgThanks
You can't. Getting the full file path of a file on the client's machine is considered a security risk, and newer browsers will only ever return the file name. Older versions of IE will give the full path however.
womp
A: 

I post this even though I'm unsure if input[type=file] behaves differently than input[type=text]. But with input[type=text], you call the val() function and not read a value member variable.

Ken Browning