2012-06-15 52 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? –