ID:183186
Sep 26 2007, 2:08 pm
|
|
I've been trying and searching for days on how to make a file system so when you click a button it opens up a window and lets you select a file of a certain type. Also after I've selected the file I want to use and the path is set and I click ok, how would I get C# to tell which file type it is?
|
In response to Kunark
|
|
Thanks Kunark, now I have a few more questions.
1. How would I find the path of the selected file? 2. How would I draw a square in my form? |
In response to Upinflames
|
|
1. It's one of the properties of the dialog after the dialog is complete:
if (myFileDialog.ShowDialog() != DialogResult.Cancel) { myFileDialog.Filter = "Text Files (*.txt)|*.txt"; myFileDialog.Title = "Open Text File"; string fileName = myFileDialog.FileName; } 2. To draw a square, first you include the GDI+ drawing libraries (System.Drawing, System.Drawing.Drawing2D, etc.), then in the visual editor, edit the OnPaint event and add code. It goes something like this: private void OnPaint(object sender, PaintEventArgs e) { SolidBrush brush = new SolidBrush(Color.Red); e.Graphics.DrawRectangle(brush, 33, 33, 99, 99); } |
In response to Kunark
|
|
Thanks again Kunark
|
As for the extension, you have to get the path of the file from the File object returned from the dialog, and do:
extension = path_string.SubString(path_string.lastIndexOf(".txt"));
That should answer your questions.
I would give you more specific terminology, but I've only had web development on the brain for the past two or three months so I'd need a refresher on C# first.