Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Filename check with extention

Filename check with extention

Scheduled Pinned Locked Moved C#
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    Yogesh Tayade
    wrote on last edited by
    #1

    Hi All, I have browse button to select a .hex file, this file name should always have 3 underscores and .hex as extention (for eg. TestHex_1_1_1.hex). I had written a code by using split & it works. But if foldername contains any underscore then it will not work. This is my code. private void btnOpenFolder1_Click(object sender, EventArgs e) { openFileDialog1.ShowDialog(); openFileDialog1.ValidateNames = true; textBox1.Text = openFileDialog1.FileName; char[] cr ={ '_' }; string[] str = textBox1.Text.Split(cr); if (str.Length != 4 || textBox1.Text.Substring(textBox1.Text.LastIndexOf("."), 4).ToLower() != ".hex") { textBox1.Text = ""; MessageBox.Show("File name or file extention is not valid."); } hexPath = textBox1.Text; } Please give me any suggestion.

    M 1 Reply Last reply
    0
    • Y Yogesh Tayade

      Hi All, I have browse button to select a .hex file, this file name should always have 3 underscores and .hex as extention (for eg. TestHex_1_1_1.hex). I had written a code by using split & it works. But if foldername contains any underscore then it will not work. This is my code. private void btnOpenFolder1_Click(object sender, EventArgs e) { openFileDialog1.ShowDialog(); openFileDialog1.ValidateNames = true; textBox1.Text = openFileDialog1.FileName; char[] cr ={ '_' }; string[] str = textBox1.Text.Split(cr); if (str.Length != 4 || textBox1.Text.Substring(textBox1.Text.LastIndexOf("."), 4).ToLower() != ".hex") { textBox1.Text = ""; MessageBox.Show("File name or file extention is not valid."); } hexPath = textBox1.Text; } Please give me any suggestion.

      M Offline
      M Offline
      Malmberg
      wrote on last edited by
      #2

      Check out System.IO.Path which has methods for getting extention from a path as well as filename from a path.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups