.net 程序发布后xml文件找不到的两种解决方法
自己做项目需要用智能客户端发布,我遇到了个问题就是程序中的xml文件在发布后找不到了。经过在网上查询和自己的试验发现这两个方法都可以解决这个问题。
方法1
右键winUI项目,发布-〉应用程序文件....->选择xml文件-〉发布状态改为“数据文件(自动)”
在程序里取xml路径的写法
file = Application.CommonAppDataPath+@"\text\text.xml";
这个方法有个问题就是在调试环境下不能取到正确的路径,只有发布的时候取的路径对。
方法2
右键winUI项目,发布-〉应用程序文件....->选择xml文件-〉发布状态改为“包括”
在程序里取xml路径的写法
file = System.AppDomain.CurrentDomain.BaseDirectory + @"\text\text.xml";
这个方法调试和发布取到的路径都是对的。
相关文档:
function init() {
var viewChartID = 0;
var viewChartSum = "" ;
reportName = document.getElementById("reportName").value;
xmlDoc=loadXMLDoc("./charreport/xml/viewChart.xml");
x=xmlDoc.getElementsByTagName('viewChart')[0].childNodes;
for (i=0;i<x.length;i++ ......
/*
* 主要作用;
* 从xml读取游戏配置信息或保存
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Forms;
using System.IO;
using System.Xml;
using System.Reflection;
namespace Game
{
class Config
{
Ke ......
//判断该xml文档是否存在,不存在则创建
if (!File.Exists(Constants.SYS_CONFIGURE_URL + @"\SaveAccount.xml"))
&nbs ......
<html xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<STYLE>
v\:* { Behavior: url(#default#VML) }
body {
background-color:DarkGoldenrod;
margin-left: 10px;
&nbs ......
public string ConvertDataTableToXML(DataTable xmlDS)
{
MemoryStream stream = null;
XmlTextWriter writer = null;
try
{
stream = new MemoryStream();
writer = new XmlTextWriter(stream, Encoding.Default);
......