943,833 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Marked Solved
  • Views: 58332
  • ASP.NET RSS
Nov 12th, 2007
0

Open file Dialog in asp.net

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Nareshp_123 is offline Offline
18 posts
since Nov 2007
Nov 14th, 2007
0

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.

ASP.NET Syntax (Toggle Plain Text)
  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>
Reputation Points: 66
Solved Threads: 56
Posting Pro in Training
Fungus1487 is offline Offline
459 posts
since Apr 2007
Nov 15th, 2007
0

Re: Open file Dialog in asp.net

Click to Expand / Collapse  Quote originally posted by Fungus1487 ...
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.

ASP.NET Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Nareshp_123 is offline Offline
18 posts
since Nov 2007
Nov 15th, 2007
0

Re: Open file Dialog in asp.net

ok then just simply add an onchange event to your FILE input.
ASP.NET Syntax (Toggle Plain Text)
  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.
Reputation Points: 66
Solved Threads: 56
Posting Pro in Training
Fungus1487 is offline Offline
459 posts
since Apr 2007
Nov 16th, 2007
0

Re: Open file Dialog in asp.net

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Nareshp_123 is offline Offline
18 posts
since Nov 2007
Dec 5th, 2007
0

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Nareshp_123 is offline Offline
18 posts
since Nov 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Help with ArrayList as returned argument
Next Thread in ASP.NET Forum Timeline: Load Report Failed





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC