首页 > 解决方案 > 程序打包后添加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();```

标签: c#

解决方案


尝试写入另一个文件夹。您可以Environment.SpecialFolder.ApplicationData用作写入文件的地方。

也许这个链接会有所帮助: 链接


推荐阅读