top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

WP Silverlight vs Universal Apps : Check file exist in Local Storage C#?

+2 votes
301 views
WP Silverlight vs Universal Apps : Check file exist in Local Storage C#?
posted Feb 27, 2015 by Puhal

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
 
Best answer

When we move from Silverlight to WinRT can feel some gaps, especially when trying to check if a file exists or not in the isolated / local storage.

WindowsPhone Silverlight:

 IsolatedStorageFile.FileExists("FileName");  

WindowsPhone Store(WinRT):

In WindowsPhone store 8.1 ,We will use the GetFileAsync function, this function returns the file data if it exists, throwing an exception if it does not exist.

public  static  async Task < bool > FileExists ( this  StorageFolder folder, String filepath)    
{    

#if WINDOWS_APP    
return  await folder.TryGetItemAsync (filepath)! = null ;    
#endif    

#if WINDOWS_PHONE_APP    

try    
{    
await folder.GetFileAsync (filepath);    
return  true ;    
}    
catch  
{    
return  false ;    
}    
#endif    
}    
answer Mar 3, 2015 by Jdk
...