我想在点击按钮后通过打开的文件对话框选择一个mp3文件,并将文件名更改为已指定的字符串。问题是,当我将TagLib.File.Create()的文件路径作为变量插入时,我得到了一个FileNotFound异常。代码如下:
public partial class Form1 : Form
{
OpenFileDialog ofd = new OpenFileDialog();
string location = null;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
ofd.ShowDialog();
location = ofd.SafeFileName;
var target = TagLib.File.Create(location);
target.Tag.Title = "it works";
target.Save();
}
}发布于 2018-07-28 18:06:34
试着使用
location = ofd.FileName;来获取完整的文件路径,而不是
location = ofd.SafeFileName;这就给了你文件名。
此外,最佳实践还包括:
TagLib.File target = null;
if (!string.IsNullOrEmpty(location) && File.Exists(location))
{
target = TagLib.File.Create(location);
}
else
{
//log or print a warning
}https://stackoverflow.com/questions/51570009
复制相似问题