10
Answers

How fill TexBox by filepath from FileUpload control

Alexander Dracka

Alexander Dracka

11y
7.6k
1
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)