DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   ASP.NET (http://www.daniweb.com/forums/forum18.html)
-   -   Open file Dialog in asp.net (http://www.daniweb.com/forums/thread96414.html)

Nareshp_123 Nov 12th, 2007 9:10 am
Open file Dialog in asp.net
 
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

Fungus1487 Nov 14th, 2007 9:23 am
Re: Open file Dialog in asp.net
 
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>

Nareshp_123 Nov 15th, 2007 12:56 am
Re: Open file Dialog in asp.net
 
Quote:

Originally Posted by Fungus1487 (Post 469644)
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.

Fungus1487 Nov 15th, 2007 8:40 am
Re: Open file Dialog in asp.net
 
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.

Nareshp_123 Nov 16th, 2007 2:57 am
Re: Open file Dialog in asp.net
 
No it did'nt worked .....
Attribute 'onchange' is not a valid attribute of element 'input'.....

Nareshp_123 Dec 5th, 2007 3:07 am
Re: Open file Dialog in asp.net
 
ok i did it but not as per requirement with one textbox for selecting path with button and another to display the file


All times are GMT -4. The time now is 3:03 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC