English 中文(简体)
道路为何发生变化
原标题:Why the path is getting changed

我的法典以两种不同形式检索了一条可怕的生态道路。 如果我选择一种方式开启档案和处理档案,那么,回到另一种形式时,我会发现一个Dracotry例外错误。 我用不同的手法来走这条路。

第二,我称:

       string strFilePath2;
       strFilePath2 = Directory.GetCurrentDirectory();
       strFilePath2 = Directory.GetParent(strFilePath2).ToString();
       strFilePath2 = Directory.GetParent(strFilePath2).ToString();
       strFilePath2 = strFilePath2 + "\ACH";

我首先呼吁:

       strFilePath = Directory.GetCurrentDirectory();
       strFilePath = Directory.GetParent(strFilePath).ToString();
       strFilePath = Directory.GetParent(strFilePath).ToString();
       strFilePath = strFilePath + "\ACH\" + Node;

在偷渡期间,我正在从第二步走某些道路,但我所期望的道路不是。 谁能告诉为什么?

最佳回答

您是否检查了目前的名录的价值?

<代码>OpenFileDialog通常将改变目前的名录。 http://msdn.microsoft.com/en-us/library/system.windows.forms.filedialog.restoredirectory.aspx” rel=“nofollow noreferer”>。 财产:

OpenFileDialog ofd = new OpenFileDialog();

ofd.RestoreDirectory = true ; // this will not modify the current directory

除此以外,你正在整理你的法典样本。 在NET中,最好采用静态<代码>Path.Combine方法。 这种方法将检查是否存在抗反弹(或无论系统具有何种路径分离特性),如果缺失,将自动插入:

strFilePath = Path.Combine(strFilePath, "ACH");
问题回答

<代码>OpenFileDialog和SaveFileDialog改变了目前的工作道路,而目前的工作道路是空洞的。 您可以人工重新制定,或制定<代码>。 恢复目录=真实;,以便在选择档案后重新改动。 如果你使用<条码>FolderBrowserDialog,如果你仍然收到这一问题,就不得不人工操作。

这往往取决于<代码>FolderBrowserDialog、<代码>OpenFileDialog或两者兼有。 这些方言(和其他组成部分)自动改变了您的运行申请工作目录。

我的建议是,如果存在某种用户互动,则避免使用相对途径。





相关问题
Bring window to foreground after Mutex fails

I was wondering if someone can tell me what would be the best way to bring my application to the foreground if a mutex was not able to be created for a new instance. E.g.: Application X is running ...

How to start WinForm app minimized to tray?

I ve successfully created an app that minimizes to the tray using a NotifyIcon. When the form is manually closed it is successfully hidden from the desktop, taskbar, and alt-tab. The problem occurs ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

Handle DataTable.DataRow cell change event

I have a DataTable that has several DataColumns and DataRow. Now i would like to handle an event when cell of this DataRow is changed. How to do this in c#?

Apparent Memory Leak in DataGridView

How do you force a DataGridView to release its reference to a bound DataSet? We have a rather large dataset being displayed in a DataGridView and noticed that resources were not being freed after the ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

WPF-XAML window in Winforms Application

I have a Winforms application coded in VS C# 2008 and want to insert a WPF window into the window pane of Winforms application. Could you explain me how this is done.

热门标签