愚蠢的问题,但做一个方法,使用ITextSharp
创建收据的PDF和文件的名称是基于客户名称和购买日期,但如果我在同一天有2次购买ITextSharp
只是覆盖文件。我想要它,所以它在文件名的末尾添加了(1),(2)等
string aux1 = data.getString("select full_name from clients where id=" + cboClient.SelectedValue);
string aux2 = getWrittenDate(DateTime.Today);
SaveFileDialog sfd = new SaveFileDialog();
sfd.FileName = "receipt" + aux1 + aux2 + ".pdf";
Document doc = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35);
PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream((sfd.FileName), FileMode.Create));
doc.Open();
您可以使用File.Exists(filePath)
检查文件是否已存在,并在这种情况下手动重命名。
一个好的解决方案是将购买时间添加到文件名以使其唯一。
希望这可以帮助 :)