0

Hi every one,pls am trying to copy the content of my fileupload unto an hidden text box so that users will not have to copy it manually,but it just copies the file name wit exception of the path.I need the path name but in IE9,firefox,opera all i get is the file name without file path pls somebody help.
this is my code

protected void Button1_Click(object sender, EventArgs e)
    {
        string filepath = FileUpload1.PostedFile.FileName;
        hiddentext.text = filepath;

    }

have also tried this

protected void Button1_Click(object sender, EventArgs e)
    {
          string s1 = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
          string s2 = string.Copy(s1);
           hiddentext.text  = s2;
}

It gives same answer pls help.

Thanks in advance

Edited by mike_2000_17: Fixed formatting

5
Contributors
4
Replies
6
Views
6 Years
Discussion Span
Last Post by G_Waddell
0

The file path is going to be the file path on the server where you want to the file to go, not the file path on the local client machine.

Do you have the folder structure setup properly on the server? This will have nothing to do with the browser you are using.

0

hi...For an security reason you can get the loded file path in fileupload control...

0

Browsers and html5 have changed so that the real filepath is replaced with 'C:\fakepath' for end user security

0

Hi,

Are you trying to get the page to validate something else on th form e.g. a textbox before uploading the file?

If so, you do your validation client side that way you will not lose your file path as the form will not be submitted like this:

'on code behind on page load
btnUpload.attributes.add("onclick", "return ValdateForm()")
<!--On Client Side-->
<script language="javascript" type="text/javascript">
function ValdateForm(){
  var txtTextBox = null;
  if(document.getElementById) {
    txtTextBox = document.getElementById("<%=txtTextBox.clientID%>"); 
  }
  else if(document.all) {
   txtTextBox = document.all["<%=txtTextBox.clientID%>"];
  }
  if(txtTextBox.value==null||txtTextbox.value==""){
   alert("Fill me in!");
   return false;
  }
  else {
   return true;
  }
}
</script>

If the Textbox has no value the javascript will return a false and stop the button submitting the form (leaving your filepath in place). If there is a value in the textbox, the javascript returns true, the form submits and eveything goes on as normal.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.