- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我是 C# 的新手,正在尝试解析 XML 文档,但我一直收到找不到目录的错误
显然我的 xml 文件和数据文件夹在程序启动时没有被复制到 \bin\Debug
下面是我的代码:
收到错误:
An unhandled exception of type 'System.IO.DirectoryNotFoundException' occurred in mscorlib.dll
Additional information: Could not find a part of the path 'C:\Users\Alfred\Source\Workspaces\CIS151_MEY\AlfredM Books XML\AlfredM Books XML\bin\Debug\Data\Books.xml'.
类文件:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;
using System.Xml.Linq;
using System.Reflection;
namespace AlfredM_Books_XML
{
class XmlHelper
{
public static XDocument GetBookDocument()
{
string appPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
FileInfo asm = new FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location);
FileInfo fi = new FileInfo(asm.DirectoryName + @"\Data\Books.xml");
XDocument doc = XDocument.Load(fi.FullName);
return doc;
}
}
}
这是我添加 XML 文件的地方
最佳答案
在 Solution Explorer
中选择您的 Books.xml
文件,右键单击该文件并选择 Properties
。然后将属性 Copy To Output Directory
值设置为 Copy always
。
关于c# - DirectoryNotFoundException C# 将 XML 文件加载到控制台应用程序时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32809361/
我正在尝试创建一个 named mutex ,但是当我调用构造函数时,我得到一个 DirectoryNotFoundException!为什么互斥锁试图访问文件系统,我如何知道什么是有效路径?互斥体是
我有一个为自己构建的控制台应用程序,用于重命名我下载的 .mp3 文件。该应用程序已经完美运行了好几个月,但突然在一个特定目录中向我抛出标题异常。不仅是这个目录,而且只发生在选定数量的文件上——其中
考虑以下代码片段 private void ProcessFile(string fullPath) { XmlTextReader rdr = new XmlTextReader("file
伙计们为什么我无法构建我的项目为什么会出现这个错误? Wondershare 与 Unity 有关系吗?当我想在我的 android 设备上构建我的应用程序时,为什么会出现此错误?任何帮助将不胜感激
我尝试使用的日志属于另一个与我自己的程序同时运行的程序。当我尝试制作副本时,我收到一个 DirectoryNotFoundException,指出“无法找到路径的一部分”。断言确实通过了。异常在 Fi
我制作了一个在某些目录中搜索某些文件的应用程序。当目录不存在时,它会抛出 DirectoryNotFoundException。我捕获到该异常,但它没有 DirectoryName 属性或类似 Fil
我试图在特定目录中查找所有 jpg 文件,但出现此错误 Additional information: Could not find a part of the path 'C:\Users\myPC
我是 ASP.NET MVC C# 的新手,我正在我的项目中使用 ReportViewerForMVC。有了这个https://reportviewerformvc.codeplex.com/wiki
使用 this question我想出了这段代码来保存文件 [HttpPost] public IActionResult Upload(string office, IFormFile file)
我有一个将目录路径作为字符串的方法。在该方法的开头,它检查此路径是否存在,如果不存在,则应抛出异常。我认为它可能应该抛出 DirectoryNotFoundException 或其他东西,而不是不太具
我想复制一个文件夹,我想先删除目标文件夹。所以我要删除目标文件夹然后重新创建它然后复制文件。问题是我得到 An unhandled exception of type 'System.IO.Direc
我正在尝试使用 Visual Studio 2008 中的 CoreCon API 以编程方式启动设备模拟器。当我调用 device.Connect() 时,我莫名其妙地得到了 DirectoryNo
我是 C# 的新手,正在尝试解析 XML 文档,但我一直收到找不到目录的错误 显然我的 xml 文件和数据文件夹在程序启动时没有被复制到 \bin\Debug 下面是我的代码: 收到错误: An un
我有一个在 Azure 上运行的 ASP.NET Core 应用程序。该应用程序发送各种电子邮件 - 纯文本和 HTML 格式。我在 Resources 文件夹中创建了一个名为 EmailTempla
这个问题在这里已经有了答案: Maximum filename length in NTFS (Windows XP and Windows Vista)? (15 个答案) 关闭 4 年前。 我有
try { string directory = @"D:/user/user.txt"; FileStream FS = new
try { string directory = @"D:/user/user.txt"; FileStream FS = new
我已将本地组策略编辑器中的Enable Win32 Long Paths设置为Enabled并重新启动计算机。 代码如下: string path = Environment.GetFolderPat
只是一个简单的问题(我希望):当我使用 File.Move 时,它给我一个错误: System.IO.DirectoryNotFoundException was unhandled by use
我已将 TFSService 帐户连接到我的 Azure 帐户,并尝试将 TFSService 生成的结果发布到我的 Azure 帐户。很确定我的构建定义设置正确 - 一切都编译得很好,这很棒,但每次
我是一名优秀的程序员,十分优秀!