目前我正嘗試從我的Android項目中使用Xamarin.Forms加載文件「json」。Xamarin.Forms FileStream - 找不到文件
這裏是我的代碼:
var path = @"client_secret.json";
using (var stream = new System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read))
{
}
對於小路上,我嘗試了許多不同的情況下將「client_secret.json」項目的根文件夾,文件夾的資產,二進制,二進制>調試,倉位>釋放以及對「.Droid」項目和PCL也是如此。我也嘗試將文件構建操作更改爲「內容」,「嵌入式資源」,「附加文件」,「AndroidResource」和「AndroidEnvironment」。我也試圖改變 「client_secret.json」,並使用物理路徑(d:\ APPS .... \ Project.Android \ client_secret.json),並試圖找到它在不同的文件夾:
Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads).AbsolutePath
Directory.GetFiles(Directory.GetCurrentDirectory())
Directory.GetFiles(Android.OS.Environment.RootDirectory.AbsolutePath)
Directory.GetFiles(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal))
而且還我找不到它。 「複製到輸出」文件屬性更改爲「始終複製」,仍然沒有結果。
有沒有人知道我在做什麼錯在這種情況下,使FileStream在這個文件上?
在此先感謝
嗨,謝謝你的回答。我嘗試使用3-rd選項,但在「等待GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.Load(stream).Secrets,Scopes,」user「,CancellationToken.None);」我收到「無法找到指定文件」 –
第三種選擇 - 在指定資源ID時很容易錯過並使用錯誤的名稱空間。請確保你使用的是正確的。另外,你有機會嘗試選項1或2嗎? – Ada
另外,你可以請你分享你收到的例外堆棧跟蹤。 – Ada