实现效果:

  将长文件名转换成短文件名

知识运用:

   系统API函数GetShortPathName

  [DllImport("Kernel32.dll")]
  private static extern Int16 GetShortPathName(string IpszLongPath,StringBuilder IpszShortPath,Int16 cchBuffer);

  将长文件名转换成短文件名

实现代码:

        [DllImport("Kernel32.dll")]
        private static extern Int16 GetShortPathName(string IpszLongPath,StringBuilder IpszShortPath,Int16 cchBuffer);
        private void button1_Click(object sender, EventArgs e)
        {
            if (OFDlog.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = OFDlog.FileName;
                string longName = textBox1.Text;
                StringBuilder shortName = new System.Text.StringBuilder(256);
                GetShortPathName(longName,shortName,256);
                string myInfo = "长文件名:" + longName;
                myInfo += "\n" + "短文件名:" + shortName;
                label2.Text = myInfo;
            }

  

相关文章:

  • 2021-08-17
  • 2021-06-20
  • 2021-12-09
  • 2019-05-24
  • 2021-11-04
  • 2021-10-11
猜你喜欢
  • 2022-01-04
  • 2022-12-23
  • 2021-10-07
  • 2021-11-07
  • 2021-10-26
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案