你好,我想在isolatedStora从文件的路径的Windows Phone 7如何获得isolatedStorageFileStream.name(抛出异常......)
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的,但不与工作完美寡妇电话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
不是targetStream.Name会不会与fileName一样?为什么不使用它呢? – 2013-05-09 09:11:30
否...文件名为object_6200.jpg,targetStreamName为:\\ Applications \\ Data \\ 32C945F5-B5D7-4287-95CE-B814F446339F \\ Data \\ IsolatedStore \\ object_image_6200.jpg。 我需要完整的路径来显示图像的一个枢轴。 而在Windows Phone 8上,targetStream.Name是 C:\\ Data \\ Users \\ DefApps \\ AppData \\ {EF1C8978-ACB9-4231-97A7-6F2CFC10AC5C} \\ Local \\ object_image_6200.jpg – 2013-05-09 09:23:07
Where你从文件中获取?我无法重现您的问题。尝试发布完整的方法代码。 – 2013-05-09 09:43:23