posts - 124,  comments - 29,  trackbacks - 0

OpenFileDialog对话框影响当前工作目录,比如,当前工作目录为一个项目的bin/debug目录下,配置文件也在这下面,当OpenFileDialog选择文件时,目录改为选择文件所在目录,这样程序中的  xmlDoc.Load("FileTyp.xml");就找不到文件FileTyp.xml了,解决此问题是方法是,OpenFileDialog之前保存一下当前目录,之后再还原:如下:

       private void butSelectFile_Click(object sender, EventArgs e)
        {
            string curWD = System.IO.Directory.GetCurrentDirectory();
            OpenFileDialog fd = new OpenFileDialog();
            if (fd.ShowDialog(this) == DialogResult.OK)
            {           
                localFileName = fd.SafeFileName;
                FileInfo fi = new FileInfo(fd.SafeFileName);
                String path = fi.Directory.ToString();
                this.localFilePath = path + "\\" + localFileName;
                textFile.Text = localFilePath;
               
            }
            System.IO.Directory.SetCurrentDirectory(curWD);

        }

posted on 2008-10-31 09:11 天书 阅读(600) 评论(0)  编辑 收藏 引用

<2008年9月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

常用链接

留言簿(5)

随笔档案

文章分类

文章档案

好友的Bolg

搜索

  •  

最新评论

阅读排行榜

评论排行榜