10
Reply

How fill TexBox by filepath from FileUpload control

Alexander Dracka

Alexander Dracka

Aug 17 2013 10:37 AM
7.6k
Hello i got hidden FileUpload control, textBox where i wanna write url adrres or! filepath to some file, and button for call FileUpload. My problem is that I need  instantly after user checks in fileupload control some file and close popup window, fill TextBox with filepaths of that file. I know how show filepath but i need do it automatically and that trap for me. Here is what i got so far. Last piece of code is how i got filepath but I need that user use FileUpload 
protected void Page_Load(object sender, EventArgs e)
{
  btnFileUpload.Attributes.Add(
    "onclick",
    "document.getElementById('" + FileUpload2.ClientID + "').click();");  
}
<div class="ViewContent">
  <asp:FileUpload ID="FileUpload2" runat="server" Width="317px" style="display: none"/>
  <input id="btnFileUpload" type="button" value="Add" runat="server" style="width: 70px" />
    <asp:TextBox ID="TextBox2" runat="server" Width="310px"/>
</div>
if (FileUpload2.PostedFile != null)
{
  TextBox2.Text = System.IO.Path.GetFullPath(FileUpload2.PostedFile.FileName);
}

Answers (10)