User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 456,234 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,754 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 10037 | Replies: 5 | Solved
Reply
Join Date: Nov 2007
Posts: 18
Reputation: Nareshp_123 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Nareshp_123 Nareshp_123 is offline Offline
Newbie Poster

Help Open file Dialog in asp.net

  #1  
Nov 12th, 2007
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2007
Location: Birmingham
Posts: 378
Reputation: Fungus1487 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 38
Fungus1487's Avatar
Fungus1487 Fungus1487 is offline Offline
Posting Whiz

Re: Open file Dialog in asp.net

  #2  
Nov 14th, 2007
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>
When Autumn Falls [ http://www.whenautumnfalls.co.uk ] &&
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Reply With Quote  
Join Date: Nov 2007
Posts: 18
Reputation: Nareshp_123 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Nareshp_123 Nareshp_123 is offline Offline
Newbie Poster

Question Re: Open file Dialog in asp.net

  #3  
Nov 15th, 2007
Originally Posted by Fungus1487 View Post
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.
Reply With Quote  
Join Date: Apr 2007
Location: Birmingham
Posts: 378
Reputation: Fungus1487 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 38
Fungus1487's Avatar
Fungus1487 Fungus1487 is offline Offline
Posting Whiz

Re: Open file Dialog in asp.net

  #4  
Nov 15th, 2007
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.
When Autumn Falls [ http://www.whenautumnfalls.co.uk ] &&
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Reply With Quote  
Join Date: Nov 2007
Posts: 18
Reputation: Nareshp_123 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Nareshp_123 Nareshp_123 is offline Offline
Newbie Poster

Re: Open file Dialog in asp.net

  #5  
Nov 16th, 2007
No it did'nt worked .....
Attribute 'onchange' is not a valid attribute of element 'input'.....
Last edited by Nareshp_123 : Nov 16th, 2007 at 3:01 am.
Reply With Quote  
Join Date: Nov 2007
Posts: 18
Reputation: Nareshp_123 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Nareshp_123 Nareshp_123 is offline Offline
Newbie Poster

Re: Open file Dialog in asp.net

  #6  
Dec 5th, 2007
ok i did it but not as per requirement with one textbox for selecting path with button and another to display the file
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 5:09 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC