2012-04-04 32 views
0

我在我的應用程序的IsolatedStorage中有一些文件。文件類型是不同的,比如說doc,xls,ppt,pdf,mp3,mov,jpg,png等等。我需要打開這些文件。我怎樣才能做到這一點。如何在wp7中打開文件?

回答

2

嘗試用名稱及其擴展名打開它

byte [] data;

 using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication()) 
     { 

      using (IsolatedStorageFileStream isfs = isf.OpenFile(image.jpg, FileMode.Open, FileAccess.Read)) 
      { 
       data = new byte[isfs.Length]; 
       isfs.Read(data, 0, data.Length); 
       isfs.Close(); 
      } 

     } 


     MemoryStream ms = new MemoryStream(data); 

     BitmapImage bi = new BitmapImage(); 
     bi.SetSource(ms); 
     Image img = new image(); 
     img.source = bi 

如果它是圖像嘗試將位圖圖像的源設置爲內存流ms。

+0

當我嘗試將內存流設置爲圖像源時,它會引發異常。錯誤信息是「Unspecified error」 – 2012-04-04 12:31:53

+0

嘗試像這樣BitmapImage bi = new BitmapImage(); bi.SetSource(ms); 圖像img =新圖像(); img.source = bi; – 2012-04-04 13:07:51

+0

即使將var更改爲BitmapImage,也會發生相同的錯誤 – 2012-04-05 03:48:47