你好我想从isolatedStora中的文件中获取路径
using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream targetStream = isoStore.OpenFile(fileName, FileMode.Create, FileAccess.Write))
{
// Initialize the buffer for 4KB disk pages.
byte[] readBuffer = new byte[4096];
int bytesRead = -1;
// Copy the thumbnail to isolated storage.
while ((bytesRead = e.Result.Read(readBuffer, 0, readBuffer.Length)) > 0)
{
targetStream.Write(readBuffer, 0, bytesRead);
}
targetStream.Close();
_myObject.object_image = targetStream.Name ;
}
}
这适用于 Windows Phone 8 但不适用于 Widows phone 7。在 Windows Phone 7 上会引发异常
{System.MethodAccessException: Attempt to access the method failed: System.IO.IsolatedStorage.IsolatedStorageFileStream.get_Name()
at deepView.Model.HistoryHelper.<saveObjectToHistory>b__1(Object s, OpenReadCompletedEventArgs e)
at System.Net.WebClient.OnOpenReadCompleted(OpenReadCompletedEventArgs e)
at System.Net.WebClient.OpenReadOperationCompleted(Object arg)
at System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)
at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at System.Delegate.DynamicInvokeOne(Object[] args)
at System.MulticastDelegate.DynamicInvokeImpl(Object[] args)
at System.Delegate.DynamicInvoke(Object[] args)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.Dispatch(DispatcherPriority priority)
at System.Windows.Threading.Dispatcher.OnInvoke(Object context)
at System.Windows.Hosting.CallbackCookie.Invoke(Object[] args)
at System.Windows.Hosting.DelegateWrapper.InternalInvoke(Object[] args)
at System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(IntPtr pHandle, Int32 nParamCount, ScriptParam[] pParams, ScriptParam& pResult)
}
有人可以帮帮我吗?
编辑: 完成代码,我在其中获取图像并将其保存到隔离存储(完美适用于 WP8),突出显示的部分是我尝试获取名称并将其保存到数据库的位置
WebClient client = new WebClient();
client.OpenReadCompleted += (s, e) =>
{
try
{
string fileName = "Shared/Media/object_image_6200.jpg";
//Save thumbnail as JPEG to isolated storage.
using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
{
if (!isoStore.FileExists(fileName))
{
using (IsolatedStorageFileStream targetStream = isoStore.OpenFile(fileName, FileMode.Create, FileAccess.Write))
{
// Initialize the buffer for 4KB disk pages.
byte[] readBuffer = new byte[4096];
int bytesRead = -1;
// Copy the thumbnail to isolated storage.
while ((bytesRead = e.Result.Read(readBuffer, 0, readBuffer.Length)) > 0)
{
targetStream.Write(readBuffer, 0, bytesRead);
}
**_historyObject.object_image = targetStream.Name;**
targetStream.Close();
HistoryClass existingHistoryObject = null;
existingHistoryObject = db.FindObjectByObjectId(GlobalVariables.responseObject.object_id);
if (existingHistoryObject == null)
{
db.HistoryObjects.InsertOnSubmit(_historyObject);
db.SubmitChanges();
}
}
}
}
}
catch (Exception ex)
{
//EXCEPTION HANDLING
}
};
//get object image for history view
client.OpenReadAsync(new Uri("http://example.de/object_6200.jpg", UriKind.Absolute));
……
但是当执行到达target.Name时抛出异常