TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Eugene Gabriyelov
NA
5
0
Open file using OpenFileDialog Class
Sep 28 2009 2:15 PM
I am trying to do something very simple but am having a hard time making it work. I need to open a browse file dialog onclick of a button (windows application) and allow the user to select a file from a specified directory and open the file when onclick of the open button in the open file dialog. My code is below. For some reason it doesnt work. Please help!
private
void
btnHandouts_Click(
object
sender,
EventArgs
e)
{
string
fileNamePath;
string
fileNameOnly;
OpenFileDialog
fdlg =
new
OpenFileDialog
();
fdlg.Title =
"Open File"
;
fdlg.InitialDirectory =
@"..\Handouts"
;
fdlg.Filter =
"All files (*.*)|*.*|All files (*.*)|*.*"
;
fdlg.CheckFileExists =
true
;
fdlg.FilterIndex = 2;
fdlg.RestoreDirectory =
true
;
if
(fdlg.ShowDialog() ==
DialogResult
.OK)
{
fileNamePath = fdlg.FileName;
fileNameOnly =
Path
.GetFileName(fileNamePath);
FileStream
fileStream =
new
FileStream
(
@"..\Handouts\"
+ fileNameOnly,
FileMode
.Open);
fileStream.Close();
}
}
Reply
Answers (
4
)
Having a gridview to disappear when doing changes in a listbox
user defined asp.net