Issue with debugging Visual Studio 2010 solution that utilises FileDialog from the Vista API

*爱你&永不变心* 提交于 2019-12-06 13:45:18
granadaCoder

I came across this and I figured out a fix in my case.

Original Code:

OpenFileDialog fdlg = new OpenFileDialog();
string tempDirectoryName = @"..\SomeFolder\"; /* Note, the use of a relative directory*/
fdlg.InitialDirectory = tempDirectoryName ;
Nullable<bool> result = fdlg.ShowDialog();

I then changed it to:

OpenFileDialog fdlg = new OpenFileDialog();
string tempDirectoryName = @"..\SomeFolder\"; /* Note, the use of a relative directory*/
string massagedDirectoryName = System.IO.Path.**GetFullPath**(tempDirectoryName);
fdlg.InitialDirectory = massagedDirectoryName; /*Note, this is now the full folder name */
Nullable<bool> result = fdlg.ShowDialog();

And it did not bomb on me anymore.

Mine was almost same scenario.

My scenario:

Code was WPF app under VS2008 and worked. (3.5 Framework was the Target Framework) I up-converted to code to VS2010 (4.0 Framework was the Target Framework). Then this new issue arose.

Both code bases were running on Windows 7 x64.

.............

My full error was:

 Value does not fall within the expected range.
    at MS.Internal.Interop.HRESULT.ThrowIfFailed(String message)
    at MS.Internal.AppModel.ShellUtil.GetShellItemForPath(String path)
    at Microsoft.Win32.FileDialog.PrepareVistaDialog(IFileDialog dialog)
    at Microsoft.Win32.FileDialog.RunVistaDialog(IntPtr hwndOwner)
    at Microsoft.Win32.CommonDialog.ShowDialog()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!