Rene Sá
Rene Sá

Reputation: 4

String from file names - How remove the extension?

I'm developing a windows phone app. I saved many files on Isolated storage and i need shows them (file names) on ListBox. My code works fine, but file names is show with extension (filename.doc). I want show file names without extension (filename).

My code:

IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();

string directory = "./preVenda/*.*";
string[] filenames = myIsolatedStorage.GetFileNames(directory);

List0.Items.Add(filenames);

I tried use "Remove" method, but not work.

Upvotes: 0

Views: 1782

Answers (1)

Steve
Steve

Reputation: 216293

You could use Path.GetFileNameWithoutExtension

foreach(string file in filenames)
    List0.Items.Add(System.IO.Path.GetFileNameWithoutExtension(file));

Also, you could try without an explicit loop (I suppose that list0 is a System.Windows.Control.ListBox)

list0.ItemsSource = filenames.Select(d => Path.GetFileNameWithoutExtension(d)).ToList();

(Warning. Not able to test this now)

Upvotes: 4

Related Questions