我正在构建一个WinForms应用程序,通过SaveFileDialog
从用户那里接收路径。
以下是我的代码的相关部分。 我该如何确定路径pcapFile
是否有效并存在?
private void btnBrowse_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialogBrowse = new SaveFileDialog();
saveFileDialogBrowse.Filter = "Pcap file|*.pcap";
saveFileDialogBrowse.Title = "Save an pcap File";
saveFileDialogBrowse.ShowDialog();
pcapFile = saveFileDialogBrowse.FileName; //do whatever you like with the selected filename
if (pcapFile != "")
{
FileInfo fileInfo = new FileInfo(pcapFile);
tbOutputFileName.Text = fileInfo.FullName;
}
}