Wrox Programmer Forums
|
VB.NET General VB.NET discussions for issues that don't fall into other VB.NET forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 6th, 2005, 03:19 PM
mh mh is offline
Authorized User
 
Join Date: Mar 2005
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default open file dialog box

I'm trying to open up a file dialog so the user can select a file from the directory once the user clicks a button. From there, I want to send that file name to a textbox. But first, I need to be able to open up a dialog which I'm unable to do. This is what I have so far:

Private Sub cmdExc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExc.Click
        Dim myStream As Stream
        Dim openFileDialog1 As New OpenFileDialog

        openFileDialog1.InitialDirectory = "c:\"
        openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
        openFileDialog1.FilterIndex = 2
        openFileDialog1.RestoreDirectory = True

        If openFileDialog1.ShowDialog() = DialogResult.OK Then
            myStream = openFileDialog1.OpenFile()
            If Not (myStream Is Nothing) Then
                   myStream.Close()
            End If
        End If
    End Sub

It keeps saying that Stream, OpenFileDialog, and DialogResult are undefined. Am I doing something wrong? I would appreciate it if someone could help me. Thanks.

 
Old April 6th, 2005, 07:41 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

This is just a guess, but looking at your MessageBox post I am going to assume that this is a web application.

The OpenFileDialog box is a Windows forms control. That's why you are getting the error about the OpenFileDialog and the DialogResult.

J
 
Old April 7th, 2005, 09:03 AM
mh mh is offline
Authorized User
 
Join Date: Mar 2005
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, you are right. It is a web application. Is there any way I can get a dialog box for my web application? Thanks.

 
Old April 7th, 2005, 10:15 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

You can use an Input element.

<INPUT id="YourID" value="YourFileName" style="WIDTH: 317px; HEIGHT: 22px" type="file" size="33">

Look this up on a search engine to find out all attributes for this type of Input.

On a side note (and I am not trying to push you off to a different forum), you may get more responses if you post your topics about .aspx pages in the .aspx forums as opposed to general VB.Net.

J
 
Old April 7th, 2005, 11:58 AM
mh mh is offline
Authorized User
 
Join Date: Mar 2005
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for pointing me in the right direction. But, I have a question regarding disabling it. Right now, it is disabled if the dropdownlist is not 2 and a button is clicked. If it is 2, then I want to enable it. So, by default it is disabled until 2 is selected. But I keep on getting this error:

document.form1.txtCvsFile is null or not an object

And here is my code:
function NewWindow()
{
if (document.getElementById("dlstep").value == "2")
     {
     document.form1.txtCvsFile.disabled = false
     }
return false;
     }

txtCvsFile is my file input element and dlstep is my dropdownlist. Can someone please tell me how to go about doing this? Thanks.

 
Old April 7th, 2005, 12:26 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

The only way I know of to get a dialog like you are talking about is with the html file upload control.
It puts a textbox and a browse button on the web page side-by-side, and the browse button puts up a dialog like you describe.

Internet browsers have a lot of protection built in to avoid the user's files being viewed by malicious web pages, which also prohibits the sort of thing that you are trying. (Security issues are starting to make me feel insecure!)
 
Old April 10th, 2005, 03:24 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Try using the same method to get at the file input object:

getElementById("txtCvsFile")
 
Old April 11th, 2005, 10:15 AM
mh mh is offline
Authorized User
 
Join Date: Mar 2005
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for everyone's help.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Open dialog box... hooking shikhar_ntd Visual C++ 0 April 13th, 2006 12:25 AM
Call windows' "Open file" dialog box from an swf vicky_barse Flash (all versions) 1 December 30th, 2005 12:47 PM
URGENT: automate - OPEN A FILE DIALOG BOX,SELECT chichi120976 Excel VBA 1 December 13th, 2003 05:22 PM
Open File Dialog Box KennethMungwira VB.NET 3 August 3rd, 2003 09:44 PM
Open File Dialog Box KennethMungwira VB.NET 2 June 27th, 2003 04:36 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.