由于某种原因,我收到的网络名称无法找到。我尝试将“myUniqueFileName”应用于pdfwriter行时出错。所以它不是权限问题,因为它使用下面的第一个代码行。有什么想法吗?
这可行(找到路径)
PdfWriter.GetInstance(Doc1, New FileStream(path & "/Doc1.pdf", FileMode.Create))
这不起作用
PdfWriter.GetInstance(Doc1, New FileStream(path & myUniqueFileName, FileMode.Create))
这是完整的代码
Dim Doc1 As New Document
Dim path As String = "\\ServerAddress\PDFs"
Dim myUniqueFileName = String.Format("{0}.pdf", Guid.NewGuid())
PdfWriter.GetInstance(Doc1, New FileStream(path & myUniqueFileName, FileMode.Create))
Doc1.Open()
Dim test As String
test = Session("PDF")
Doc1.Add(New Paragraph(test))
Doc1.Close()
答案 0 :(得分:2)
使用Path.Combine,在串联字符串时缺少反斜杠字符。
Dim Doc1 As New Document
Dim path As String = "\\ServerAddress\PDFs"
Dim myUniqueFileName = String.Format("{0}.pdf", Guid.NewGuid())
PdfWriter.GetInstance(Doc1, New FileStream(System.IO.Path.Combine(path,myUniqueFileName), FileMode.Create))
Doc1.Open()
Dim test As String
test = Session("PDF")
Doc1.Add(New Paragraph(test))
Doc1.Close()