Open file Dialog in asp.net

Please support our ASP.NET advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
Thread Solved
Reply

Join Date: Nov 2007
Posts: 18
Reputation: Nareshp_123 is an unknown quantity at this point 
Solved Threads: 0
Nareshp_123 Nareshp_123 is offline Offline
Newbie Poster

Open file Dialog in asp.net

 
0
  #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
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 437
Reputation: Fungus1487 is on a distinguished road 
Solved Threads: 50
Fungus1487's Avatar
Fungus1487 Fungus1487 is offline Offline
Posting Pro in Training

Re: Open file Dialog in asp.net

 
0
  #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.

  1. <form name="form1"/>
  2. <input type="file" name="filediag" style="display:none" />
  3. <input type="button" value="browse..."
  4. onclick="document.form1.filediag.click()" />
  5. </form>
When Autumn Falls [ http://www.whenautumnfalls.co.uk ] &&
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 18
Reputation: Nareshp_123 is an unknown quantity at this point 
Solved Threads: 0
Nareshp_123 Nareshp_123 is offline Offline
Newbie Poster

Re: Open file Dialog in asp.net

 
0
  #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.

  1. <form name="form1"/>
  2. <input type="file" name="filediag" style="display:none" />
  3. <input type="button" value="browse..."
  4. onclick="document.form1.filediag.click()" />
  5. </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 Quick reply to this message  
Join Date: Apr 2007
Posts: 437
Reputation: Fungus1487 is on a distinguished road 
Solved Threads: 50
Fungus1487's Avatar
Fungus1487 Fungus1487 is offline Offline
Posting Pro in Training

Re: Open file Dialog in asp.net

 
0
  #4
Nov 15th, 2007
ok then just simply add an onchange event to your FILE input.
  1. <form name="form1"/>
  2. <input type="file" name="filediag" style="display:none"
  3. onchange="window.open(this.value, '_blank')" />
  4. <input type="button" value="browse..."
  5. onclick="document.form1.filediag.click()" />
  6. </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 Quick reply to this message  
Join Date: Nov 2007
Posts: 18
Reputation: Nareshp_123 is an unknown quantity at this point 
Solved Threads: 0
Nareshp_123 Nareshp_123 is offline Offline
Newbie Poster

Re: Open file Dialog in asp.net

 
0
  #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 Quick reply to this message  
Join Date: Nov 2007
Posts: 18
Reputation: Nareshp_123 is an unknown quantity at this point 
Solved Threads: 0
Nareshp_123 Nareshp_123 is offline Offline
Newbie Poster

Re: Open file Dialog in asp.net

 
0
  #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 Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC