[英]Access to the path is denied when uploading file to program files\some commercial program
我得到一個錯誤:
Access to the path 'C:\Program Files (x86)\MetaTrader FIX\experts\indicators\Awesome.ex4' is denied./n at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at System.IO.File.Create(String path)
at Iron_loader.Program.Main(String[] args) in C:\Users\Damian\Documents\Visual Studio 2010\Projects\Iron loader\Iron loader\Program.cs:line 55
當我從\\ bin \\ Debug運行我的exe文件時。 我不知道為什么。 在目標目錄中沒有此類文件,因此我認為安全性存在問題,因為當我從VS以管理員身份運行程序時,一切正常。
我正在嘗試將文件上傳到其他程序的文件夾(不是我的)。 如何復制該文件?
File.Create(newPath);
File.Copy(pathOfFileFromMyDebugDirectory, newPath);
檢查文件夾的權限。 用戶沒有修改/完全控制權限。
選擇文件夾上的屬性,然后選擇“安全性”選項卡,並檢查當前用戶或您的應用程序用戶的權限。 正在運行。
如果操作系統和WindowsXP以下,則環氧樹脂將不會在C:\\ ProgramFilesx86中讀寫,因為uac。
您必須以管理員權限啟動應用程序。
問候。
...請參閱下面的編輯
我認為部分問題是“進程”尚未釋放文件句柄。 嘗試這個:
using (Stream stream = File.Create(newPath))
{}
File.Copy(pathOfFileFromMyDebugDirectory, newPath);
在using塊中單擊右括號時,將調用基本流Dispose()
方法,並且應釋放所有資源-包括進程的文件句柄。
編輯
您在“ File.Create”調用中遇到異常了嗎? 我誤讀了您給的錯誤。 如果在Create()方法中遇到異常,則需要確保您有權 寫入路徑。
我相信,當您解決供股問題時,您可能會收到一個例外,說明該句柄已被另一個進程使用。 如果是這樣,請使用我上面的建議進行修復。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.