2012-06-15 54 views
1

我正在开发一个WPF应用程序。我让用户选择一些图片,然后我想将该图片保存在同一个Project directoy中的EmployeePics目录中。 下面是截图:将图像复制到WPF中的图像目录中

enter image description here


我已经写了下面的代码,但它不工作:

string appPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "EmployeePics\\"); 
File.Copy(Chosen_File, appPath + Chosen_File); 


我得到以下异常:
enter image description here

+0

你有IO许可吗?字符串“Chosen_File”和“appPath”中有什么? – gliderkite

回答

2

尝试使用File.Copy方法。如果不是不可能,请提供更多细节。

更新:

要解决的图片目录,你可以使用System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "EmployeePics")

更新2

全码:

File.Copy(Chosen_File, Path.Combine(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "EmployeePics"), Path.GetFileName(Chosen_File)))

+0

这将得到的exe的位置,那么你只需要追加路径。链接:www.csharp-examples.net/get-application-directory/ –

+0

@JohnKZ请看我的帖子,我已经添加了代码,但它不工作! – Azeem

+0

使用'Path.Combine'而不是'appPath + Chosen_File'。你真的使用WPF,而不是WinForms? –