发布应用程序错误后,在查找数据库和xml文件的路径时发生错误

时间:2011-08-12 17:24:37

标签: c#

我有OS XP俄语版,安装程序后显示错误“俄语中的路径无法读取” - 以我的方式解释。有人有任何想法吗?感谢


    public string getDBpath() {
                string path1 = System.Windows.Forms.Application.StartupPath;
                string path2 = "safer.sdf";
                string path3 = Path.Combine(path1, path2);
                return path3;

            }

            public string getXmlPath() {
                string path1 = System.Windows.Forms.Application.StartupPath;
                string path2 =  @"data/fp.xml";
                string path3 = Path.Combine(path1, path2);
                return path3;
            }

            public string getXmlPathTxt() {
                string path1 = System.Windows.Forms.Application.StartupPath;
                string path2 = @"data/xml_data.txt";
                string path3 = Path.Combine(path1, path2);
                return path3;
            }

2 个答案:

答案 0 :(得分:0)

不确定这是否可以解决问题,但您可以尝试将System.Windows.Forms.Application.StartupPath更改为Assembly.GetExecutingAssembly().Location,看看是否可以解决问题。

public string getDBpath() {
            string path1 = Assembly.GetExecutingAssembly().Location;
            string path2 = "safer.sdf";
            string path3 = Path.Combine(path1, path2);
            return path3;

        }

        public string getXmlPath() {
            string path1 = Assembly.GetExecutingAssembly().Location;
            string path2 =  @"data/fp.xml";
            string path3 = Path.Combine(path1, path2);
            return path3;
        }

        public string getXmlPathTxt() {
            string path1 = Assembly.GetExecutingAssembly().Location;
            string path2 = @"data/xml_data.txt";
            string path3 = Path.Combine(path1, path2);
            return path3;
        }

答案 1 :(得分:0)

您可以尝试使用Thread.GetDomain().BaseDirectory代替System.Windows.Forms.Application.StartupPath

如果这不起作用,我会建议您附加到已部署的应用程序版本。因此,您可以轻松添加Debugger.Launch();,以便创建您的广告。