2013-05-10 20 views
0

我有一個應用程序,它讀取xml數據,進行一些更改並將其保存到word文檔中。當我第一次運行應用程序時,基本URI是「C:\ Documents \ Visual Studio 2010 \ Projects \ WindowsFormsApplication1 \ WindowsFormsApplication1 \ bin \ Debug」。但是,當我第二次運行時沒有重新啓動應用程序的基礎URI更改爲上次保存的位置,我得到一個錯誤說xml文件沒有found.Below是代碼的一部分。我在哪裏弄錯了將字符串加載到Windows c中的xml文檔時出錯#

string xmlSource = string.Empty; 

      if (string.IsNullOrEmpty(xmlSource)) 

       xmlSource = "Dictionary.xml"; 

       XmlDocument doc = new XmlDocument(); 
       doc.Load(xmlSource); 
       FileStream usrFs = null; 
      try 
      { 

       usrFs = new FileStream(xmlSource, FileMode.Open, FileAccess.Read, 
           FileShare.ReadWrite); 

      } 

      catch (IOException ex) 
      { 
       MessageBox.Show(ex.Message); 
      } 
      try 
      { 

       doc.Load(usrFs); 

      } 
      catch (Exception ex) 
      { 

       MessageBox.Show(ex.Message); 
      } 

回答

1

使用完整路徑而不是相對路徑。

xmlSource = System.AppDomain.CurrentDomain.BaseDirectory + "\\Dictionary.xml";