我需要您的帮助,我找不到任何解决的主题。
我有一个应用程序,我想创建一个.cvs文件,该方法采用我声明的路径并重新编写它,并将应用程序目录路径添加到我声明的路径的前面,这是编码,然后是错误。
Public fileNameReport As String = ""
fileNameReport = ""
fileNameReport = "C:\Users\guillermo.velez\Documents\01.Guillermo V\Tests\" & Now & " Reject Report.csv"
fileNameReport = fileNameReport.Replace("/", "")
fileNameReport = fileNameReport.Replace(":", "")
If Not File.Exists(fileNameReport) Then
System.IO.File.Create(fileNameReport).Dispose()
End If
错误如下:System.IO.DirectoryNotFoundException:'找不到路径的一部分'C:\ 224135-6 Reject Control \ 224135-6 Reject Control \ bin \ Debug \ C \ Users(我的用户名)\ Documents \ 01.Guillermo V \ Tests \ 1132020 110900 AM Reject Report.csv'。
你不应该:
用空字符串代替
fileNameReport = fileNameReport.Replace(":", "")
这将路径转换c:\
为c\
请使用DateTime格式选项将日期作为文件名的一部分,例如
fileNameReport = string.Format("{0:ddMMyyyyhhmmss}Reject Report.csv", DateTime.Now)
dirName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) // this will return folder where executing assembly is located but you can put any value here
fileNameReport = Path.Combine(dirName, fileNameReport)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句