473,396 Members | 1,590 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Openfiledialog

When trying to use this control, how do you change the default filename, OPENFILEDIALOG1 is what is showing up in filename textbox? Any hint or clue to what I am doing incorrectly.

Here is the code that I am using:

With OpenFileDialog1
.InitialDirectory = "C:"
.Filter = "All Files (*.*)|*.*"
.CheckFileExists = True
TextBox1.Text = (DataGridView1.SelectedCells(0).Value.ToString())
hit = TextBox1.Text
'TextBox1.Text = (DataGridView1.SelectedCells(0).Value.ToString())

'open Dialiog
If .ShowDialog = Windows.Forms.DialogResult.OK Then
'm_InputStream = CType(OpenFileDialog1.OpenFile(), System.IO.StreamReader)
m_inputstream = New System.IO.StreamReader(OpenFileDialog1.OpenFile)
If m_inputstream Is Nothing Then
Throw New Exception("Error opening the file")
End If

' OpenFileDialog1.ToString = hit


End If
End With
May 11 '07 #1
5 1550
SammyB
807 Expert 512MB
.FileName
Expand|Select|Wrap|Line Numbers
  1. With OpenFileDialog1
  2.      .InitialDirectory = "C:"
  3.      .Filter = "All Files (*.*)|*.*"
  4.      .CheckFileExists = True
  5.      .FileName = "WORK.LOG"
  6.      If .ShowDialog = Windows.Forms.DialogResult.OK Then
  7.          MsgBox(.FileName)
  8.      End If
  9. End With
May 11 '07 #2
How do you get it the file to open? I can pull up the file dialog and the filename is the textbox, but when I click on open, nothing happens...at least I don't see anything happening.
I would like to be able to view the actual document when I click on open.

Any suggestions.
It's like downloading an attachment and viewing it. But it is in a windows application instead of a web based. I know it probably would be easy in web.
May 25 '07 #3
SammyB
807 Expert 512MB
LOL, the dialog only gives you the filename, it does not open, read, or write. You'll need to use StreamWriter and/or StreamReader. It's explained at http://support.microsoft.com/kb/304427. --Sam
May 25 '07 #4
mwalts
38
LOL, the dialog only gives you the filename, it does not open, read, or write. You'll need to use StreamWriter and/or StreamReader. It's explained at http://support.microsoft.com/kb/304427. --Sam
Right, also it seems to me that you may just want to open the file with whatever is the default application for that file type. If that is true, then you should look into the Process class (in the System.Diagnostics namespace).

Specifically with the StartInfo.UseShellExecute property set to true.
Yes I could tell you exactly how to use it, but google it first, it'll be good practice

Good luck,

-mwalts
May 25 '07 #5
SammyB
807 Expert 512MB
Also, I keep forgetting the the OpenFileDialog has a OpenFile method that returns a Stream object, http://msdn2.microsoft.com/en-us/lib....openfile.aspx
May 25 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Jody Gelowitz | last post by:
VS.NET 2002 and 2003 are installed. ..NET Framework 1.0 and 1.1 installed Program running under VisualBasic.NET 2002 with .NET Framwork 1.0 I am experiencing a problem with ADO.NET where the...
3
by: bobrad | last post by:
MAYBE SOMEBODY CAM HELP I AM USING THE FOLLOWING CODE TO GET A LOCATION OF A FILE IN A WINFORM DIALOG OpenFileDialog openFileDialog = new OpenFileDialog(); OpenFileDialog.Filter = " Access...
2
by: don | last post by:
has anyone experienced problems with interactions between OpenFileDialog and FileStream? When I select "open" from an OpenFileDialog the subsequent calls to FileStream do not create a file. If I do...
4
by: Nagachandra Sekhar Grandhi | last post by:
I am facing a problem with OpenFileDialog. It is as follows. I opened OpenFileDialog dialog box and selected a folder in it. After selecting the folder when i tried to delete the same folder in...
8
by: e-mid | last post by:
why does not openFileDialog have closed event? i want to do something; as soon as the dialog closes. is there a way to do this?
6
by: barbara_dave | last post by:
Hi, All, I want to use the openfiledialog to open different extension files in different directory( only one type files at one time). I set the OpenFiledialog InitialDirectory and Filter...
8
by: marcus.kwok | last post by:
I am having a weird problem and I have can't figure out why it is happening. I create an OpenFileDialog and set a filename filter. When the dialog first opens, the filter works correctly, and...
1
by: sam | last post by:
OpenFileDialog appears to be "holding onto" the parent folder of a selected file until the application using the dialog quits. After creating a folder containing a file, I attempted to select...
3
by: Martijn Mulder | last post by:
It strikes me that System.Windows.Forms.OpenFileDialog seems te 'remember' which directory it was in last, even when a new OpenFileDialog-object is created for every access to the file system....
0
by: mbewers1 | last post by:
Hi I'm having a problem trying to get a customised OpenFileDialog() to fulfil my requirements. The code for this custom-built dialog has been taken from another site...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.