[英]c#.net overwrite prompt not working
I have a user data report that needs to be saved as pdf, but when I put the overwrite prompt to true the overwrite message when there is a filename that exist is not showing. 我有一个需要保存为pdf的用户数据报告,但是当我将覆盖提示设置为true时,当不存在存在的文件名时,将显示覆盖消息。 Here's my code. 这是我的代码。
SaveFileDialog svg = new SaveFileDialog();
svg.FileName = "Data Report - All Books";//set default file name
svg.Filter = "Pdf Files|*.pdf";
if (svg.ShowDialog() == DialogResult.OK)
{
svg.OverwritePrompt = true;//tell user to overwrite existing file name
using (FileStream stream = new FileStream(svg.FileName + ".pdf", FileMode.Create))
{
Document pdfDoc = new Document(PageSize.A1, 10f, 10f, 10f, 0f);
PdfWriter.GetInstance(pdfDoc, stream);
pdfDoc.Open();
pdfDoc.Add(pdfTable);
pdfDoc.Close();
stream.Close();
}
MetroMessageBox.Show(this, "Successfully save PDF report.", "SUCESS!", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
You have to set the overwrite prompt before dialog is shown. 在显示对话框之前,您必须设置覆盖提示。 MSDN does mention OverWritePrompt by default is set to true. MSDN确实提到OverWritePrompt默认情况下设置为true。
SaveFileDialog svg = new SaveFileDialog();
svg.FileName = "Data Report - All Books";//set default file name
svg.Filter = "Pdf Files|*.pdf";
//This needs to be before dialog is shown.
svg.OverwritePrompt = true;//tell user to overwrite
if (svg.ShowDialog() == DialogResult.OK)
{
using (FileStream stream = new FileStream(svg.FileName + ".pdf", FileMode.Create))
{
Document pdfDoc = new Document(PageSize.A1, 10f, 10f, 10f, 0f);
PdfWriter.GetInstance(pdfDoc, stream);
pdfDoc.Open();
pdfDoc.Add(pdfTable);
pdfDoc.Close();
stream.Close();
}
MetroMessageBox.Show(this, "Successfully save PDF report.", "SUCESS!", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.