1)您不應該在Windows Phone上使用Directory.CreateDirectory
。相反,因爲你是在獨立存儲操作,你需要使用:
var file = IsolatedStorageFile.GetUserStoreForApplication();
file.CreateDirectory("myDirectory");
2)下載文件可以通過Web客戶端來完成這樣:
WebClient client = new WebClient();
client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_OpenReadCompleted);
client.OpenReadAsync(new Uri("your_URL"));
void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
var file = IsolatedStorageFile.GetUserStoreForApplication();
using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream("file.epub", System.IO.FileMode.Create, file))
{
byte[] buffer = new byte[1024];
while (e.Result.Read(buffer, 0, buffer.Length) > 0)
{
stream.Write(buffer, 0, buffer.Length);
}
}
}
直接在這種情況下創建一個目錄是可選。如果您需要將文件保存在嵌套的文件夾結構中,則可以將文件路徑設置爲/Folder/NewFolder/file.epub。
3)要在獨立存儲枚舉文件,你可以使用:
var file = IsolatedStorageFile.GetUserStoreForApplication();
file.GetFileNames();
那如果文件位於IsoStore的根源。如果這些位於目錄中,則必須設置搜索模式並將其傳遞到GetFileNames
- 包括文件夾名稱和文件類型。對於每個單個文件,可以使用以下模式:
DIRECTORY_NAME\*.*
要下載的文件類型是什麼? – Waleed
這是.epub文件。 – Shri