473,796 Members | 2,482 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

openFileDialog beginner's problem

Hi,

How do I simply open a text file into a textbox? I know that in C++ I'd use
something like:
if(OpenDialog1->Execute())
Memo1->Lines->LoadFromFile(O penDialog1->FileName);

How can I do it in vsnet c#?

THX
Libor(Czech rep.)
Nov 15 '05 #1
2 5736
Bonzo:
How do I simply open a text file into a textbox? I know that in C++ I'd use something like:
if(OpenDialog1->Execute())
Memo1->Lines->LoadFromFile(O penDialog1->FileName);

How can I do it in vsnet c#?


The RichTextBox class, for example, has a method called "LoadFile". Here's
some sample code copy-pasted from the .NET Framework help file:

public void LoadMyFile()
{
// Create an OpenFileDialog to request a file to open.
OpenFileDialog openFile1 = new OpenFileDialog( );

// Initialize the OpenFileDialog to look for RTF files.
openFile1.Defau ltExt = "*.rtf";
openFile1.Filte r = "RTF Files|*.rtf";

// Determine whether the user selected a file from the OpenFileDialog.
if(openFile1.Sh owDialog() == System.Windows. Forms.DialogRes ult.OK &&
openFile1.FileN ame.Length > 0)
{
// Load the contents of the file into the RichTextBox.
richTextBox1.Lo adFile(openFile 1.FileName,
RichTextBoxStre amType.PlainTex t);
}
}

--
take care,
Fabian Ottjes
Purposesoft (http://www.purposesoft.com)

"There are gods, ... They're the most extraordinary beings on earth. Never
doubt it." -Swoop
Nov 15 '05 #2
Great, Thanks
"Fabian Ottjes" <no****@nospam. org> píąe v diskusním příspěvku
news:%2******** **********@TK2M SFTNGP12.phx.gb l...
Bonzo:
How do I simply open a text file into a textbox? I know that in C++ I'd

use
something like:
if(OpenDialog1->Execute())
Memo1->Lines->LoadFromFile(O penDialog1->FileName);

How can I do it in vsnet c#?


The RichTextBox class, for example, has a method called "LoadFile". Here's
some sample code copy-pasted from the .NET Framework help file:

public void LoadMyFile()
{
// Create an OpenFileDialog to request a file to open.
OpenFileDialog openFile1 = new OpenFileDialog( );

// Initialize the OpenFileDialog to look for RTF files.
openFile1.Defau ltExt = "*.rtf";
openFile1.Filte r = "RTF Files|*.rtf";

// Determine whether the user selected a file from the OpenFileDialog.
if(openFile1.Sh owDialog() == System.Windows. Forms.DialogRes ult.OK &&
openFile1.FileN ame.Length > 0)
{
// Load the contents of the file into the RichTextBox.
richTextBox1.Lo adFile(openFile 1.FileName,
RichTextBoxStre amType.PlainTex t);
}
}

--
take care,
Fabian Ottjes
Purposesoft (http://www.purposesoft.com)

"There are gods, ... They're the most extraordinary beings on earth. Never
doubt it." -Swoop

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
1376
by: Amir Dekel | last post by:
Hello everyone, First, I have to say that Python is one of the coolest programing languages I have seen. And now for the problem (must be a silly one): When I import a module I have wrote, and then I find bugs, it seems that I can't import it again after a fix it. It always shows the same problem. I try del module but it doesn't work. (I use Python 2.4 with the ActivePython pack (PythonWin IDE)
2
2590
by: Lee Garrington | last post by:
Hey, Recently I decided to learn C++ so that I could port over one of my Java programs to make it faster. Basically everything has ported over fine so far until I came up against the following problem.... The problem involves 2 classes. A Game class and a Solver class. The Game class updates the game board etc. and the Solver class is called upon when it needs to solve the board. To do this I have an instance of Solver declared in...
0
3724
by: Jari Kujansuu | last post by:
I am trying to learn to use jing through JARV interface and I have read JARV User's Guide (http://iso-relax.sourceforge.net/JARV/JARV.html). I have downloaded jingjarv-examples.zip from JARV User's Guide page and latest jing version 20030619 from jing home page. I can run jing successfully from command line like this (which I guess proves that schema should be correct) C:\Temp\APU> java -jar jing.jar schema.xsd valid.xml
0
1149
by: Albinas | last post by:
Dear all, I am a beginner in VB.NET and I have just taken the course 2565. (So, you can see how fresh I am.) I am creating a custom textbox and adding some new attributes to the textbox. However, I want to have a list of possible value to be displayed in the property window for the corresponding attribute. For example, you can select values in the BorderStyle.
7
1469
by: smartbeginner | last post by:
I got from a book a 2D array(a is resolved by compiler as a=*(&a+total_columns*i+j); // ->1 And I know when I use pointer to array I should refer a=*(*(a+i)+j); ->2 Is this also resolved by the compiler to (->1) (Awkward question I know) And my main question is why we use *(a+i) here In the pointer to array notation
10
1502
by: Fabian Steiner | last post by:
I recently started learning C since I want to be able to write Python extension modules. In fact, there is no need for it, but I simply want to try something new ... I tried to implement the bubblesort algorithm in C and to use it in python; bubblesort.c compiles fine, but whenever I want to import the modul and call the function I get a segmentation fault. This is what the code looks like: static PyObject *py_bubblesort(PyObject...
3
1169
by: Toni | last post by:
Hello! I'm building an application where the user can update his own personal information in a database using a form. The program fetches the user's information from the database, fills the form with this information, then the user makes the changes that he wants, clicks the "Update" button and the updated information is sent back to the database. But I have a problem. My program is supposed to work like this: txtNamefield.text = "John...
8
1955
by: Mike Jolley | last post by:
Hello First off, I'm a student so I'm pretty new to C++, and therefore I have probably made a stupid mistake somewhere. Anyway Ive been trying to fix this 5 hours straight now, so i need a little assistance. What I'm trying to do I am using inheritance to make some bookings for a marina, which are: Booking
0
1141
by: smilyface | last post by:
Hello, I'm a beginner with python and I have a problem. I'm using Python 2.5 with PyWin32 on Windows Vista. I try to run this script Office2PDF
0
9680
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10455
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10228
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10173
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10006
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9052
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7547
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5573
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4116
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.