http://expert.csdn.net/Expert/topic/2945/2945426.xml?temp=1.908511E-02

解决方案 »

  1.   


    试试这个
    后缀名=System.IO.Path.GetExtension(文件名);
      

  2.   

    dim i as integer
    i=str.lastindex(".") //取得该文件名的最后一个。号
    newtype=str.substring(i) //取得包括,号的后缀名
    或者
    newtype=str.substring(i+1) //直接取得后缀名
      

  3.   

    dim file as new fileinfo("filepath")
    dim extentin as string=file.extention
      

  4.   

    string strFileExtention = System.IO.Path.GetExtension(fileName);
      

  5.   

    System.IO.Path.GetExtension(string path)
      

  6.   

    返回文件扩展名:System.IO.Path.GetExtension(string path)
    返回文件路径名称: System.IO.Path.GetDirectoryName(string path)
    改变或删除文件扩展名:System.IO.Path.ChangeExtension(string path,string ExtensionName)
      

  7.   

    OpenFileDialog ofd = new OpenFileDialog();
    ofd.Filter = "所有文件|*.*";
    if(ofd.ShowDialog() == DialogResult.OK)
    {
    this.textBox1.Text = ofd.FileName;
    string na = ofd.FileName.Substring(ofd.FileName.LastIndexOf(@"\")+1);
    string leng = ofd.FileName.Substring(ofd.FileName.LastIndexOf(@".")+1);
    int row = leng.Length;
    na = na.Remove(na.LastIndexOf(@"."),row + 1);
    this.textBox2.Text = na;

    FileStream ff = new FileStream(this.textBox1.Text, FileMode.Open);
    if(ff.Length > 2048000)
    {
    float r = ff.Length ;
    r = r / 1024000;  
    MessageBox.Show("附件不能超过2M", "当前附件:" + r.ToString()  +"M"); this.textBox1.Text = "";  //清空当前操作
    this.textBox2.Text = "";
    }
    ff.Close();
    }
      

  8.   

    //首先取到文件名:
    string strFileName = oFile.FileName.ToLower();
    int nIndex = strFileName.LastIndexOf(".");
    strFileName = strFileName.SubString(nIndex+1);
      

  9.   

    C#
    后缀名=filename.SubString(filename.LastIndexOf("."));