| | |
File details in to List View using a file dialog box
Please support our C# advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
![]() |
Hi, I'm pretty new to using C# and have come across a problem that I thought would be pretty simple, and it probably is but I'm stuck.
I'm trying to get a user to select a file using a file dialog box and once that has been selected to get the details of the file added to a list view (set to the detail mode).
So far I have it showing the dialog box and when the user selects the file the file path is added to the first column of the list view.
I thought that "FileName" would add only the name like "Worddocument.doc" but instead it adds "C:\Test Folder\Worddocument.doc"
I've come across the code "System.IO.Path.GetFileName" but can't get it to work. I've also tried getting anything to add in to the next column along such as "GetCreatedDate" but no luck with those either.
Has anyone any suggestions?
I'm trying to get a user to select a file using a file dialog box and once that has been selected to get the details of the file added to a list view (set to the detail mode).
So far I have it showing the dialog box and when the user selects the file the file path is added to the first column of the list view.
C# Syntax (Toggle Plain Text)
OpenFileDialog openSingleFile = new OpenFileDialog(); openSingleFile.Title = "Open a Single File"; openSingleFile.InitialDirectory = "C:"; openSingleFile.Filter = "All Files|*.*"; openSingleFile.ShowDialog(); fileinfoViewer.Items.Add(openSingleFile.FileName);
I thought that "FileName" would add only the name like "Worddocument.doc" but instead it adds "C:\Test Folder\Worddocument.doc"
I've come across the code "System.IO.Path.GetFileName" but can't get it to work. I've also tried getting anything to add in to the next column along such as "GetCreatedDate" but no luck with those either.
Has anyone any suggestions?
Here's and example of a few of the ways I've tried it. None of them have worked, but I could well not be using it in the right way though.
Here are a few of the ways I tried
I'm sure that I'm not calling it in the correct manner if none of these work. I did think that it would be possible to get file info straight from the dialog box and put it in to the list view.
Here are a few of the ways I tried
C# Syntax (Toggle Plain Text)
fileinfoViewer.Items.Add(openSingleFile.GetFileName);
C# Syntax (Toggle Plain Text)
String fileNameOnly; fileNameOnly = System.IO.Path.GetFileName((openSingleFile)); fileinfoViewer.Items.Add(fileNameOnly);
I'm sure that I'm not calling it in the correct manner if none of these work. I did think that it would be possible to get file info straight from the dialog box and put it in to the list view.
this
should be
•
•
•
•
String fileNameOnly;
fileNameOnly = System.IO.Path.GetFileName((openSingleFile));
fileinfoViewer.Items.Add(fileNameOnly);
C# Syntax (Toggle Plain Text)
String fileNameOnly; fileNameOnly = System.IO.Path.GetFileName((openSingleFile.FileName)); fileinfoViewer.Items.Add(fileNameOnly);
•
•
Join Date: Dec 2008
Posts: 1
Reputation:
Solved Threads: 0
hi
this looks bit more clear
http://www.kanbal.com/index.php?/C/f...-box-in-c.html
Regards
Kannan Chandrasekaran
this looks bit more clear
http://www.kanbal.com/index.php?/C/f...-box-in-c.html
Regards
Kannan Chandrasekaran
•
•
Join Date: Nov 2008
Posts: 44
Reputation:
Solved Threads: 4
If i'm not wrong (IF), fileopendialog will have a properties call SafeFileName or something like that. It would return the file name. To get extra information.
System.IO.FileInfo Fs = new System.IO.FileInfo(thisfile);
Then from here get the information from that object.
System.IO.FileInfo Fs = new System.IO.FileInfo(thisfile);
Then from here get the information from that object.
.Net Developer - 3D Game Designer
My Portfolio/Blog: http://www.hieu.co.uk
My Portfolio/Blog: http://www.hieu.co.uk
![]() |
Similar Threads
- Cannot find server or DNS Error - please help! (Viruses, Spyware and other Nasties)
- Shortcuts (Windows tips 'n' tweaks)
- Help (Windows NT / 2000 / XP)
- Obtain Remote Assistance by Sending an E-mail Message in Windows XP (Windows tips 'n' tweaks)
- Obtain Remote Assistance by Sending an E-mail Message in Windows XP (Windows tips 'n' tweaks)
Other Threads in the C# Forum
- Previous Thread: A couple of queries
- Next Thread: Appending the content of a text file to another text file
| Thread Tools | Search this Thread |
.net access ado.net algorithm array bitmap box buttons c# check checkbox client combobox connection console contorl control conversion cryptographyc#winformsencryption csharp database datagrid datagridview dataset datetime degrees deployment disabled displayingopenforms draganddrop drawing editor encryption enum excel file form format forms ftp function gdi+ hospitalmanagementinformationsystem i18n image imageprocessing index-error input install java label list listbox math mathematics mouseclick mysql operator oracle path photoshop picturebox pixelinversion post prime programming radians regex remoting richtextbox rows serialization server setup sleep socket sql statistics stream string table temperature text textbox thread time timer totaldays update uploadatextfile user usercontrol validation visualstudio webbrowser whileloop windowsformsapplication winforms wpf xml






