473,461 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

doubts

hai i am senthil.i am using visual studio 2005 .i want to open the file open window when i click the browse button.can you please tell me how it is happen?.thank you.
Nov 17 '08 #1
2 884
nukefusion
221 Expert 100+
You don't specify what language you are working with, but the OpenFileDialog class should do the job for you. Here are some examples:

In VB.NET:

Expand|Select|Wrap|Line Numbers
  1. Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
  2.     Dim myStream As Stream = Nothing
  3.     Dim openFileDialog1 As New OpenFileDialog()
  4.  
  5.     openFileDialog1.InitialDirectory = "c:\"
  6.     openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
  7.     openFileDialog1.FilterIndex = 2
  8.     openFileDialog1.RestoreDirectory = True
  9.  
  10.     If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
  11.         Try
  12.             myStream = openFileDialog1.OpenFile()
  13.             If (myStream IsNot Nothing) Then
  14.                 ' Insert code to read the stream here.
  15.             End If
  16.         Catch Ex As Exception
  17.             MessageBox.Show("Cannot read file from disk. Original error: " & Ex.Message)
  18.         Finally
  19.             ' Check this again, since we need to make sure we didn't throw an exception on open.
  20.             If (myStream IsNot Nothing) Then
  21.                 myStream.Close()
  22.             End If
  23.         End Try
  24.     End If
  25. End Sub
In C#:

Expand|Select|Wrap|Line Numbers
  1. private void button1_Click(object sender, System.EventArgs e)
  2. {
  3.     Stream myStream = null;
  4.     OpenFileDialog openFileDialog1 = new OpenFileDialog();
  5.  
  6.     openFileDialog1.InitialDirectory = "c:\\" ;
  7.     openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" ;
  8.     openFileDialog1.FilterIndex = 2 ;
  9.     openFileDialog1.RestoreDirectory = true ;
  10.  
  11.     if(openFileDialog1.ShowDialog() == DialogResult.OK)
  12.     {
  13.         try
  14.         {
  15.             if ((myStream = openFileDialog1.OpenFile()) != null)
  16.             {
  17.                 using (myStream)
  18.                 {
  19.                     // Insert code to read the stream here.
  20.                 }
  21.             }
  22.         }
  23.         catch (Exception ex)
  24.         {
  25.             MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
  26.         }
  27.     }
  28. }
Nov 17 '08 #2
thank you very much.
Nov 17 '08 #3

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

Similar topics

0
by: abbas reji | last post by:
--0-599929911-1059996886=:4358 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Content-Id: Content-Disposition: inline ...
1
by: Piotre Ugrumov | last post by:
I have some problems and some doubts. I have implemented a class hierachy. The base class Velivolo, from Velivolo derive Militare and Civile, from militare derive Aereo and Elicottero, from Civile...
6
by: ritesh | last post by:
Hi, I have been reading some text on C and C++ (i.e advanced books). One of the books mentioned that C++ requires a runtime support whereas C does not - what the author was trying to say was...
17
by: ranjeet.gupta | last post by:
Dear All Below are the few doubts which I got while studying about C 1. Is there any method in C by which we can process the entire string in one unit, 2. Does there exist any way to...
13
by: maadhuu | last post by:
hello everybody, i have 2 doubts . 1. is this always defined ?? int i =10; int a = i++ + i++; and also, i tried this in gcc, answer was 20, so what the sequence points for evaluation of...
6
by: Chua Wen Ching | last post by:
Hi there, I have some questions to ask... just say i have this xml file: Scenario :- Script.xml ======== <software> <settings>
2
by: VMI | last post by:
I'm having doubts as to how the compiler interprets this If statement: bool bIsTrue = true; if (! bIsTrue) { //RUN PROCESS } Here, will "RUN PROCESS" be executed? Or is this just wrong?...
1
by: Chris Leffer | last post by:
Hi. Reading some Microsoft materials about asp.net I came into two doubts. The following sentence is found on the topic "Application State" in the NET Framework documentation: "Calling Lock...
4
by: project | last post by:
Anybody can solve following doubts? 1. Normalization rules. 2. Garbage Collection 3.LinkList Posted Via Usenet.com Premium Usenet Newsgroup Services...
1
by: NagaKiran | last post by:
Hi I want to post VBA related doubts. Where can I post my doubts in VBA? thanks bye
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.