C# 如何正确指定xml文件的路径?
我很乐意为您提供任何帮助。 如何正确地指定将xml转换为文件的方式 我的应用程序正在脱离此代码C# 如何正确指定xml文件的路径?,c#,xml,C#,Xml,我很乐意为您提供任何帮助。 如何正确地指定将xml转换为文件的方式 我的应用程序正在脱离此代码 XDocument xDoc = XDocument.Load("XMLBase/Data.xml"); 对不起,gyus。我会努力改正自己 通过XamarinLive测试应用程序时没有问题 在应用程序存档和签名之后。我在手机上安装了应用程序(file.apk)。 我在电话上启动应用程序。 我翻到有问题代码的页面,应用程序崩溃了 整页代码 using System; using System.Co
XDocument xDoc = XDocument.Load("XMLBase/Data.xml");
对不起,gyus。我会努力改正自己
通过XamarinLive测试应用程序时没有问题
在应用程序存档和签名之后。我在手机上安装了应用程序(file.apk)。
我在电话上启动应用程序。
我翻到有问题代码的页面,应用程序崩溃了
整页代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using System.Xml.Linq;
using Xamarin.Forms.Xaml;
namespace App14
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class ListMain : ContentPage
{
public List<string> Students;
public ListMain ()
{
InitializeComponent ();
Students = new List<string>();
XDocument xDoc = XDocument.Load("XMLBase/Data.xml");
foreach (XElement xe in xDoc.Element("students").Elements("mainStudent"))
{
Students.Add(xe.Element("student").Value);
}
foreach (string student in Students)
{
stackLayout.Children.Add(new Label { Text = student, FontSize = 20, HorizontalOptions = LayoutOptions.StartAndExpand });
stackLayout.Children.Add(new Label { Text = "DEL", FontSize = 20, HorizontalOptions = LayoutOptions.End });
}
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用Xamarin.Forms;
使用System.Xml.Linq;
使用Xamarin.Forms.Xaml;
名称空间App14
{
[XamlCompilation(XamlCompilationOptions.Compile)]
公共部分类ListMain:ContentPage
{
公开学生名单;
公共ListMain()
{
初始化组件();
学生=新列表();
XDocument xDoc=XDocument.Load(“XMLBase/Data.xml”);
foreach(xDoc.Element(“学生”).Elements(“主体学生”)中的XElement xe)
{
添加(xe.元素(“学生”).值);
}
foreach(学生中的字符串学生)
{
stackLayout.Children.Add(新标签{Text=student,FontSize=20,horizontalpoptions=layoutuoptions.StartAndExpand});
stackLayout.Children.Add(新标签{Text=“DEL”,FontSize=20,horizontalpoptions=layoutuoptions.End});
}
}
}
}
下面的此代码片段可用作调试/学习帮助,以查看程序集中的所有清单资源名称。然后,使用程序集中所需的资源名称
var assembly = Assembly.GetExecutingAssembly();
foreach (var resourceName in assembly.GetManifestResourceNames())
System.Console.WriteLine(resourceName);
屏幕截图#1显示了上述代码片段在我的特定程序集中生成的资源名称示例。下面的代码片段中使用了红色的。下面的代码片段是我如何将资源读入字符串变量(本例中是一个.txt文件)的示例
屏幕截图2显示了资源的属性。该资源必须是嵌入式资源
,代码才能正常工作
string excludedTablesString = new StreamReader((Assembly.GetExecutingAssembly()).GetManifestResourceStream("DataReviewUtility.Resources.ExcludedTables.txt")).ReadToEnd();
屏幕截图#1
屏幕截图#2
你说的“崩溃”肯定是指你得到了一个例外。因此,如果能告诉我们确切的异常消息,那就太好了。请看一下,和/或。您认为在XMLBase文件夹中启动路径有什么原因吗?如果文件夹结构中的其他地方有一个XMLBase文件夹呢?您的程序如何知道要使用哪个?