我有一个小型WPF应用程序,我请求用户在文本框中输入文件名以对该文件进行一些处理。当我在调试模式下运行VS2010以查看是否可以通过附加代码找到该文件时,即使我知道文件存在,我也会收到错误消息文件不存在!这是代码:
string PDFfile = System.IO.Path.GetFullPath( this .txtInputFileName.Text); string strFileAttr =(File.GetAttributes(PDFfile).ToString()); if (!File.Exists(PDFfile)) { MessageBox.Show( 此文件不存在!, 错误,MessageBoxButton.OK); return ; }我的尝试: 文件PDF文件EXISTS在我运行VS2010的位置!
解决方案引用:
我已经尝试将文件的完整位置硬编码为:
string PDFfile =C: \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 你似乎错过了 .pdf 扩展名: string PDFfile = C:\\Users \\ERIC \\\ \\Desktop \\XML_Docs \\Praxair(Thailand)Co.,Ltd.pdf;您应该将Windows资源管理器配置为始终显示文件扩展名以避免这样的问题: 在Windows 10 Windows 10教程中隐藏或显示文件扩展名 [ ^ ] 你还应该考虑使用一个 OpenFileDialog [ ^ 让用户选择文件,而不是依赖它们输入完整路径并正确命名。
引用:
文件PDFfile EXISTS在我运行VS2010的位置!
检查你的应用程序的运行位置或提供一个完整路径的文件名。 要么你不在你认为的位置,要么就是文件真的机器人是否存在。
可执行文件通常位于< project directory> \bin\Debug 中,所以这就是它将检查PDF文件。如果那不是您放置文件的位置,则可以指定完整路径。
I have a small WPF application whereby I request the user to enter a file name in a Textbox to do some processing on that file. When I run VS2010 in Debug mode to see if the file can be located via the attached code, I get the error message 'File doesn't exist' even though I KNOW the file exists! Here's the code:
string PDFfile = System.IO.Path.GetFullPath(this.txtInputFileName.Text); string strFileAttr = (File.GetAttributes(PDFfile).ToString()); if (!File.Exists(PDFfile)) { MessageBox.Show("This file doesn't exist!", "Error", MessageBoxButton.OK); return; }What I have tried: The file PDFfile EXISTS in the location where I run VS2010!
解决方案 Quote:I've tried hard-coding the FULL location of the file as :
string PDFfile = "C:\\Users\\ERIC\\Desktop\\XML_Docs\\Praxair (Thailand) Co., Ltd.";You seem to be missing the .pdf extension:
string PDFfile = "C:\\Users\\ERIC\\Desktop\\XML_Docs\\Praxair (Thailand) Co., Ltd..pdf";You should configure Windows Explorer to always show file extensions to avoid problems like this: Hide or Show File Name Extensions in Windows 10 Windows 10 Tutorials[^] You should also consider using an OpenFileDialog[^] to let the user select the file, rather than relying on them to type in the full path and name correctly.
Quote:The file PDFfile EXISTS in the location where I run VS2010!
Check the location where your app is ran or give a filename with full path. Either you are not where you think you are, or the file really does bot exist.
The executable will typically be located in <project directory>\bin\Debug, so that's where it will check for the PDF file. If that's not where you put the file, you could specify the full path.更多推荐
当我执行file.getattributes()时,为什么我会收到消息'文件不存在'
发布评论