我正在尝试读取隔离存储中已创建目录中的写入文件。该文件实际上正在创建中。但是当它被读取时,会出现一个异常“IsolatedStorageFileStream 上不允许操作。”...
using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
{
if (!storage.DirectoryExists("CourseworkDirectory"))
storage.CreateDirectory("CourseworkDirectory");
XElement Coursework = new XElement(CourseworkID);
XDocument _doc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"), Coursework);
IsolatedStorageFileStream location = new IsolatedStorageFileStream("CourseworkDirectory\\"+CourseworkID, System.IO.FileMode.Create, storage);
StreamWriter file = new StreamWriter(location);
_doc.Save(file);//saving the XML document as the file
file.Close();
file.Dispose();//disposing the file
location.Dispose();
}
读取文件....
using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
{
string searchpath = System.IO.Path.Combine("CourseworkDirectory", "*.*");
foreach (string filename in storage.GetFileNames(searchpath))
{
XElement _xml;
IsolatedStorageFileStream location = new IsolatedStorageFileStream(filename, System.IO.FileMode.Open, storage);
它实际上正在获取文件名,但此时有一个例外。