c# - 程序打包后添加xml文件到项目文件夹中
问题描述
我有以下代码将数据从 datagridview 传递到 xml 文件(存储在我的设备中的此路径中:此路径:C:\Users\Multi\MainPro\bin\Debug),然后在水晶报告中显示它们,应用程序是只要我从我的设备上运行它就可以正常工作,但它在用户设备上不起作用,那么我该如何解决这个问题?
DataTable Dt = new DataTable();
Dt.Columns.Add("BrachName", typeof(string));
Dt.Columns.Add("MachNO", typeof(string));
Dt.Columns.Add("MachType", typeof(string));
Dt.Columns.Add("MachGroupName", typeof(string));
Dt.Columns.Add("MachChasiNO", typeof(string));
Dt.Columns.Add("MachFeatures", typeof(string));
Dt.Columns.Add("MachCountry", typeof(string));
Dt.Columns.Add("MachModel", typeof(int));
Dt.Columns.Add("MachIsOff", typeof(Boolean));
Dt.Columns.Add("MachIsloaning", typeof(Boolean));
Dt.Columns.Add("MachIsBorrowed", typeof(Boolean));
Dt.Columns.Add("MachNotes", typeof(string));
Dt.Columns.Add("Clarefication", typeof(string));
foreach (DataGridViewRow dgv in dgMachines.Rows)
{
Dt.Rows.Add(dgv.Cells[0].Value, dgv.Cells[1].Value, dgv.Cells[2].Value, dgv.Cells[3].Value, dgv.Cells[4].Value, dgv.Cells[5].Value, dgv.Cells[6].Value, dgv.Cells[7].Value, dgv.Cells[8].Value, dgv.Cells[9].Value,dgv.Cells[10].Value, dgv.Cells[11].Value, dgv.Cells[12].Value);
}
Ds.Tables.Add(Dt);
Ds.WriteXmlSchema("Sample.xml");
RPT.RPT_DG myreport = new RPT.RPT_DG();
myreport.SetDataSource(Ds);
RPT.FRM_Reports myform = new RPT.FRM_Reports();
myform.crystalReportViewer1.ReportSource = myreport;
myform.ShowDialog();```
解决方案
尝试写入另一个文件夹。您可以Environment.SpecialFolder.ApplicationData
用作写入文件的地方。
也许这个链接会有所帮助: 链接
推荐阅读
- matlab - MATLAB:建立置信区域
- machine-learning - 实现 norm2 损失函数的数值稳定方法
- sql-server - SQL Server 可以为 LIKE 查询使用全文索引吗?
- regex - 提取字符串中的匹配位置
- java - 如何允许 ArrayList 删除添加的对象而不覆盖或使其不可变
- javascript - 如何修复 Redis 中 HSET 的参数错误?
- cassandra - nodetool 失败,检查服务器日志 - 修复期间出错
- ios - 如何创建 CoreData 状态的快照?
- wcf - WCF:启用 TLS 1.2 并禁用 SSL 后无法连接到服务
- javascript - 自定义组件中的 connectedCallback() 是否可以根据使用的上下文以不同的方式进行解释?