Visual C# Developer Center > Visual C# Forums > Visual C# General > Seperating extension from it`s file name
Ask a questionAsk a question
 

AnswerSeperating extension from it`s file name

  • Wednesday, November 04, 2009 12:45 AMMitja Bonca Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    I would like to seperate the file into two(2) peaces :
    1. to file name
    2. to file`s extension

    I have a code, which does pretty well:
    string path = treeView1.SelectedNode.FullPath;  
    string fileName = listView1.FocusedItem.Text;  
    
    string[] SeperateFile = fileName.Split(new char[] { '.' });
    
    //then I call then in textBoxes for example:
    textBoxFileName.Text = SeperateFile[0];
    textBoxExtension.Text = SeperateFile[1];  
    

    But the problem appears if the file has more then 1 dot. I would like to kno if it`s possible to do the code which will look :
    - for the file name - to the 1st dot
    - for the extension - after the last dot

    big thanks

Answers

All Replies