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!
Reply

Join Date: Oct 2008
Posts: 2
Reputation: Typewriter is an unknown quantity at this point 
Solved Threads: 0
Typewriter's Avatar
Typewriter Typewriter is offline Offline
Newbie Poster

File details in to List View using a file dialog box

 
0
  #1
Oct 4th, 2008
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.

  1. OpenFileDialog openSingleFile = new OpenFileDialog();
  2.  
  3. openSingleFile.Title = "Open a Single File";
  4. openSingleFile.InitialDirectory = "C:";
  5. openSingleFile.Filter = "All Files|*.*";
  6.  
  7. openSingleFile.ShowDialog();
  8.  
  9. 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?
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: File details in to List View using a file dialog box

 
0
  #2
Oct 4th, 2008
Define doesnt work, what was your code, how did you use it - it works for me
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2
Reputation: Typewriter is an unknown quantity at this point 
Solved Threads: 0
Typewriter's Avatar
Typewriter Typewriter is offline Offline
Newbie Poster

Re: File details in to List View using a file dialog box

 
0
  #3
Oct 4th, 2008
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

  1.  
  2. fileinfoViewer.Items.Add(openSingleFile.GetFileName);

  1.  
  2. String fileNameOnly;
  3. fileNameOnly = System.IO.Path.GetFileName((openSingleFile));
  4. 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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: File details in to List View using a file dialog box

 
0
  #4
Oct 4th, 2008
Well the first doesnt use the getfilename from system.io.path so no that wouldnt work

the second, would work more, but again and it doesnt ask for the filename, from the class so you probably got somethng like (Object)
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 304
Reputation: Diamonddrake is a jewel in the rough Diamonddrake is a jewel in the rough Diamonddrake is a jewel in the rough 
Solved Threads: 36
Diamonddrake's Avatar
Diamonddrake Diamonddrake is offline Offline
Posting Whiz

Re: File details in to List View using a file dialog box

 
0
  #5
Oct 6th, 2008
this
String fileNameOnly;
fileNameOnly = System.IO.Path.GetFileName((openSingleFile));
fileinfoViewer.Items.Add(fileNameOnly);
should be

  1. String fileNameOnly;
  2. fileNameOnly = System.IO.Path.GetFileName((openSingleFile.FileName));
  3. fileinfoViewer.Items.Add(fileNameOnly);
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 1
Reputation: kanvishok is an unknown quantity at this point 
Solved Threads: 0
kanvishok kanvishok is offline Offline
Newbie Poster

Re: File details in to List View using a file dialog box

 
0
  #6
Dec 17th, 2008
hi
this looks bit more clear

http://www.kanbal.com/index.php?/C/f...-box-in-c.html

Regards
Kannan Chandrasekaran
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 44
Reputation: hieuuk is an unknown quantity at this point 
Solved Threads: 4
hieuuk hieuuk is offline Offline
Light Poster

Re: File details in to List View using a file dialog box

 
0
  #7
Dec 17th, 2008
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.
.Net Developer - 3D Game Designer
My Portfolio/Blog: http://www.hieu.co.uk
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC