Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
I have used a File upload control in my project.
Now, i want to display Filename selected in Fileupload control in a textbox as soon as user selects a file.
Need quick reply.
Posted 16-Apr-10 1:45am
zan0701591
Comments
Marrinavincent at 2-Nov-12 1:25am
   
I am using fileupload control inside the update panel.. It works fine.. But when i try to use the jquery validation for the controls. Button click not work.. By code is below.. please help me
 
<asp:UpdatePanel ID="updatecompanydetails" runat="server">

<script type="text/javascript">

Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(CheckValidationStatus);
</script>
<div class='validate form-horizontal'>
<table cellpadding="3" cellspacing="3">
<tr>
<td>
<div class="control-group">
<label for="uname1" class="control-label">
Company Name</label>
<div class="controls">
<asp:TextBox ID="txtcompanyname" runat="server" name="uname1" class='required'>
<asp:TextBox ID="TextBox1" runat="server" >
</div>
</div>
</td>
<td rowspan="3">
<asp:Image ID="imglogo" runat="server" />
</td>
</tr>
<tr>
<td>
<div class="control-group">
<label for="email1" class="control-label">
Website</label>
<div class="controls">
<asp:TextBox ID="txtwebsite" runat="server" class='url'>
</div>
</div>
</td>
</tr>
<tr>
<td>
<div class="control-group">
<label for="file2" class="control-label">
Logo</label>
<div class="controls">
<asp:FileUpload ID="filelogo" runat="server" onchange="callme(this)">
</div>
</div>
</td>
</tr>
</table>
<div class="form-actions">
<asp:Button ID="btnsubmit" runat="server" Text="Submit" CssClass="navigation_button btn-primary"
OnClick="btnsubmit_Click" />
<asp:Button ID="btnreset" runat="server" Text="Reset" CssClass="btn btn-danger"
OnClick="btnreset_Click" />

</div>
</div>
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

ok
the file upload control has a property called FileName you can retrieve the name of a selceted file
however ,there is another proerty called postedFile this will retrieve an object of type httpPostFile object then it has a mazing porperties as
 
FileUpload obj;//aleady exist in the web form
//send your page back to server
if(mypage.IspostedBack)
{
if(obj.hasFile)
{httppostedFile obj2=obj.postedFile;
obj2.fileName
obj2.contentType
}
}
and so on..
thank u
 
[Edit]
Ankur: The code you have given, needs a postback.
[/Edit]
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

you can use javascript to show selected file by upload controle
 
<div class="controls">
<asp:fileupload id="filelogo" runat="server" onchange="callme()" xmlns:asp="#unknown">
</asp:fileupload></div>
add textbox here
<pre lang="HTML"><div class="controls">
<asp:FileUpload ID="filelogo" runat="server" onchange="callme(this)">
</div></pre>
<asp:textbox id="txtUploadedFileName" runat="server" xmlns:asp="#unknown"></asp:textbox>
 
now write the function on .aspx file
 
<script type="text/javascript">
function callme()
  {
   document.getElementById('<%=txtUploadedFileName.ClientID%>').value=document.getElementById('<%=filelogo.ClientID %>').value;
            
  }
 
</script></script>
 
once you will select any file in uploadcontrol name of that file will reflect in text box.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

function callme(oFile) {
         document.getElementById("TextBox1").value= oFile.value;
       }
 

 
<asp:FileUpload ID="FileUpload1" runat="server"  onchange="callme(this)" />
       <asp:TextBox ID="TextBox1" runat="server"   ></asp:TextBox>
 
[Edit]
Ankur: But that would give you the full path.
You can easily extract the file name from that using javascript.
[/Edit]
Happy codding Smile | :)
  Permalink  
v2
Comments
Marrinavincent at 2-Nov-12 0:50am
   
How to solve?
I am using jquery for validating the control. Button click always shows the filename is empty.. the above code not working for fileupload control.. please help me. (All the control inside updatepanel)
 
Thank you
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

Hi,
You can use below pasted code
if(FileUploader1.HasFile)
{
string filename = FileUploader1.PostedFile.FileName.ToString();
Textbox1.Text = filename;
}
 
Thanks
Buy Lace
  Permalink  
Comments
Nagy Vilmos at 7-Jul-12 15:16pm
   
I for the spam link.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 4 Jun 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100