Hi all,
I want to have a button in a page like 'open File'. on which if user clicks, it should open open file dialog box to select a file and as soon as he clicks on the open button it should open the file (in same window or different window)
I tried using the "FileUpload 'Button but it comes in combination along textbox and button. but i need only button.
I tried <input id="file1" Type="File" runat="server"/> in html view this is also the same thing

can anybody help me such that on button click it should open file select dialog box on local machine(where the user is accessing )select file and open it.

i know how to do it in windows app but i need to do it in web app.


Thanks in advance

Naresh

you cant hide the textbox but if you set the display style property of the FORM element to 'none' and create another element of type button then using javascript you can open the dialog onClick of the button e.g.

<form name="form1"/>
    <input type="file" name="filediag" style="display:none" />
    <input type="button" value="browse..." 
            onclick="document.form1.filediag.click()" />
</form>

you cant hide the textbox but if you set the display style property of the FORM element to 'none' and create another element of type button then using javascript you can open the dialog onClick of the button e.g.

<form name="form1"/>
    <input type="file" name="filediag" style="display:none" />
    <input type="button" value="browse..." 
            onclick="document.form1.filediag.click()" />
</form>

thanks for giving it in minimum lines of script.
I had already done it upto that extent(of which i am able to get path of the file into textbox(which is not visible)but with more number of lines)ok.
but now what my question is that
after opening the 'Choosefile'dialog onClick of button('browse')
and select one (ex:- *.xml) file ->click on 'Open' button on 'Choosefile'dialog .then
it should open that file in a new browser or some editor.

ok then just simply add an onchange event to your FILE input.

<form name="form1"/>
    <input type="file" name="filediag" style="display:none"
            onchange="window.open(this.value, '_blank')" />
    <input type="button" value="browse..." 
            onclick="document.form1.filediag.click()" />
</form>

the above code will open the path of the file in a new browser window.

be aware this is only supported by I.E.6 + mozilla 1.5+ i believe as the onchange event in an INPUT of type file never used to work.

No it did'nt worked .....
Attribute 'onchange' is not a valid attribute of element 'input'.....

ok i did it but not as per requirement with one textbox for selecting path with button and another to display the file

         <input type="file" id="fileLoader" name="files" title="Load File"      /> <asp:Button ID="LoginButton" runat="server"  Text="ASP click    Me"     onclientclick="openfileDialog()"  /> <script      type="text/javascript">
       function openfileDialog() 
    {
     document.getElementById("fileLoader").click();
     }
  </script> 
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.