相关疑难解决方法(0)

StreamReader抱怨该文件不存在,但它确实存在

我有一个本地化的应用程序,可以在整个欧洲使用.

我有一个菜单选项从磁盘加载文件.

此操作在我的开发机器上运行正常但在我用于测试其他操作系统的虚拟机上不起作用_例如法语,西班牙语等.

StreamReader尝试打开文件时生成FileNotFoundException.

它说"'找不到文件C:\ Program Files\MyCompany\MyTool\bin\Files\debug.txt'"

事实是,文件确实存在,位于正确的位置并且文件名正确.

目标(法语)操作系统上的目录名称与开发机器相同.

有任何想法吗?

string ourPath =   System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);

           try
        {
            System.IO.StreamReader sr = System.IO.File.OpenText(ourPath + @"\bin\Files\debug.txt");
            string input = null;
            while ((input = sr.ReadLine()) != null)
            {
                m_text.Append(input);
            }
            sr.Close();
        }
        catch (System.IO.FileNotFoundException)
        {
            MessageBox.Show("LoadDebugOptions: File Not Found: " + ex.Message);
        }
Run Code Online (Sandbox Code Playgroud)

c# localization filenotfoundexception streamreader

12
推荐指数
2
解决办法
3万
查看次数

如何检查文件夹中文件的名称

我尝试了我在这个帖子上找到的东西,但没有完全按照我想要的方式工作......我有一个名为photos它的文件夹may有图片或没有.在picture's namematriculation客户端的.我需要传递matriculationas parameter并检查是否有一个picture带有matriculation我传递的名称parameter

我试过这个:

public void VerifyPhoto(string matriculation)
        {
            string path = Txt_PhotosPath.Text;
            var file = Directory.GetFiles(path, matriculation + ".jpg");

        }
Run Code Online (Sandbox Code Playgroud)

我怎么检查它是否找到了图片?我试图比较这个,file != null但它不适用于var类型.有提示吗?debuging我看到它发现了这张照片,因为有一个,String[1]但我不知道check它...

---更新--- path:C:"\ Users\admin\Desktop\photos" matriculation:"607659.jpg"有一个带有该名称的文件,但它一直在返回false错误的内容?

 string path = Txt_PhotosPath.Text;
            string filename = string.Format("{0}.jpg", matriculation);
            if (Directory.Exists(path))
            {
                if (File.Exists(Path.Combine(path, filename)))
                {
                    return true;
                }
                else …
Run Code Online (Sandbox Code Playgroud)

c# visual-studio-2010 winforms

3
推荐指数
1
解决办法
1256
查看次数