winform newbie
Messages   Related Types
This message was discovered on ASPFriends.com 'winforms-cs' list.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

dave wanta (VIP)
hi all,
I have a large multi-line text box. I need to load the contents of a file into the text box. I'd like to have a browse-to button, that you click, and it will show the file-common dialog window about browsing to a text file.

Does anyone have any examples for something like that? Can someone point me in the right direction?

thanks,
dave
Reply to this message...
 
    
Kladiva, Jay
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

--------------InterScan_NT_MIME_Boundary
Content-Type: multipart/alternative;
    boundary="----_=_NextPart_001_01C1FDD6.A1F940A0"

------_=_NextPart_001_01C1FDD6.A1F940A0
Content-Type: text/plain;
    charset="iso-8859-1"

Dave,

Try something like this:

private FileStream OpenFile()
{
// Display an OpenFileDialog and show the read-only files...

OpenFileDialog dlgOpenFile = new OpenFileDialog();
dlgOpenFile.ShowReadOnly = true;

if(dlgOpenFile.ShowDialog() == DialogResult.OK)
{

// If ReadOnlyChecked is true, use OpenFile method to
// open the file with read-only access.

if(dlgOpenFile.ReadOnlyChecked == true)
{
return (FileStream)dlgOpenFile.OpenFile();

}

// Otherwise, open the file with read-write access...

else
{
string path = dlgOpenFile.FileName;
return new FileStream(path, System.IO.FileMode.Open,
System.IO.FileAccess.ReadWrite);
}

}

return null;

}

Jay

-----Original Message-----
From: dave wanta [mailto:Click here to reveal e-mail address]
Sent: Friday, May 17, 2002 1:45 PM
To: winforms-cs
Subject: [winforms-cs] winform newbie

hi all,
I have a large multi-line text box. I need to load the contents of a file
into the text box. I'd like to have a browse-to button, that you click, and
it will show the file-common dialog window about browsing to a text file.

Does anyone have any examples for something like that? Can someone point me
in the right direction?

thanks,
dave
| [winforms-cs] member Click here to reveal e-mail address = YOUR ID |
http://www.asplists.com/asplists/winforms-cs.asp = JOIN/QUIT

------_=_NextPart_001_01C1FDD6.A1F940A0
Content-Type: text/html;
    charset="iso-8859-1"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">

<META content="MSHTML 6.00.2600.0" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><SPAN class=449371019-17052002><FONT face=Arial color=#0000ff
size=2>Dave,</FONT></SPAN></DIV>
<DIV><SPAN class=449371019-17052002></SPAN> </DIV>
<DIV><SPAN class=449371019-17052002></SPAN><SPAN class=449371019-17052002><FONT
face=Arial color=#0000ff size=2>Try something like
this:</FONT></SPAN> </DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV>
<DIV>private FileStream OpenFile()<BR>  
{<BR>      // Display an OpenFileDialog and show the
read-only files...<BR><BR>      OpenFileDialog
dlgOpenFile = new OpenFileDialog();<BR>     
dlgOpenFile.ShowReadOnly = true;<BR><BR><BR>     
if(dlgOpenFile.ShowDialog() ==
DialogResult.OK)<BR>     
{<BR><BR>         // If ReadOnlyChecked
is true, use OpenFile method
to<BR>         // open the file with
read-only access.<BR><BR>        
if(dlgOpenFile.ReadOnlyChecked ==
true)<BR>        
{<BR>            return
(FileStream)dlgOpenFile.OpenFile();<BR><BR>        
}<BR><BR>         // Otherwise, open the
file with read-write
access...<BR><BR>        
else<BR>        
{<BR>            string
path =
dlgOpenFile.FileName;<BR>           
return new FileStream(path, System.IO.FileMode.Open,
<BR>                 
System.IO.FileAccess.ReadWrite);<BR>        
}<BR><BR><BR>     
}<BR><BR>      return null;<BR><BR><BR>  
}</DIV>
<P style="DISPLAY: none"><SPAN class=lang style="DISPLAY: none"><SPAN
class=449371019-17052002>Jay</SPAN></SPAN></P>
<P style="DISPLAY: none"> </P><FONT face=Tahoma size=2>-----Original
Message-----<BR><B>From:</B> dave wanta
[mailto:Click here to reveal e-mail address]<BR><B>Sent:</B> Friday, May 17, 2002 1:45
PM<BR><B>To:</B> winforms-cs<BR><B>Subject:</B> [winforms-cs] winform
newbie<BR><BR></FONT>
<BLOCKQUOTE>
<DIV><FONT face=Arial size=2>hi all,</FONT></DIV>
<DIV><FONT face=Arial size=2>I have a large multi-line text box. I need to
load the contents of a file into the text box. I'd like to have a browse-to
button, that you click, and it will show the file-common dialog window about
browsing to a text file.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Does anyone have any examples for something like
that?  Can someone point me in the right direction?</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>thanks,</FONT></DIV>
<DIV><FONT face=Arial size=2>dave</FONT></DIV>| [winforms-cs] member
Click here to reveal e-mail address = YOUR ID |
http://www.asplists.com/asplists/winforms-cs.asp = JOIN/QUIT
</BLOCKQUOTE></BODY></HTML>

------_=_NextPart_001_01C1FDD6.A1F940A0--

--------------InterScan_NT_MIME_Boundary--

Reply to this message...
 
    
Ryan Trudelle-Schwarz
If you use a rich text box it has built in ability to load a file into =
itself. Then you just need to make an OpenFileDialog and pass the =
filename that that retrieves into the rich text box.

Otherwise, just load up a file object based on the path returned from =
the OpenFileDialog and dump that into your textbox.

I can shoot you some sample code for this if you need it.

Not sure about the browse to part though.

-----Original Message-----
From: dave wanta [mailto:Click here to reveal e-mail address]=20
=20
hi all,
I have a large multi-line text box. I need to load the contents of a =
file into the text box. I'd like to have a browse-to button, that you =
click, and it will show the file-common dialog window about browsing to =
a text file.
=20
Does anyone have any examples for something like that? Can someone =
point me in the right direction?
=20
thanks,
dave

---
[This E-mail scanned for viruses by Declude Virus]

Reply to this message...
 
 
System.IO.FileAccess
System.IO.FileMode
System.IO.FileStream
System.Windows.Forms.DialogResult
System.Windows.Forms.OpenFileDialog




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com