Prologue:While discussing new features of Silverlight 5 in my previous articles today we shall discuss that but with a different topic. The important new feature in Silverlight 5 is Evaluated trust.What is Evaluated Trust in Silverlight?Evaluated Trust in Silverlight is for accessing the File System of a host; the accessing Silverlight Out Of Browser Application should be trusted by the Silverlight run time. How to enable Evaluated Trust? Let us discuss that in this article, stay tuned!Evaluated Trust in Silverlight 4:In the earlier version of Silverlight, i.e. Silverlight 4 we had only Limited Access to the file system. Limited access means that we can only access the Windows Special Folders like MyDouments. Though, we can access the entire file system using COM interoperability. To know how to use COM in a Silverlight application please read this article. Evaluated Trust in Silverlight 5:In Silverlight 5, Evaluated Trust gives you access permission to the entire file system in the machine, even external storage devices like Pen Drives without using COM interoperability. Using this evaluated trust of the Silverlight application we can access [Read/Write] the files and folders anywhere if your application has Evaluated Trust.Also the earlier version of Silverlight did not allow access to the local file systems in an In-Browser Silverlight application. But in Silverlight 5, you can access the file system in In-Browser applications also.So we have Evaluated Trust to access the Entire File System. We should use this feature in our application, right? Okay let us develop a Silverlight Out Of Browser application which explorers the entire file system. Name the Application File Explorer in Silverlight 5.We can see how to use this Evaluated Trust feature in Silverlight 5 Application by creating a simple Demo application called File Explorer.Preparing the Solution:Fire up the VS 2010; create a Silverlight application project with the name "FileExplorerInSilverlight5Beta" as shown in the figure. Follow the figure [No: #].Let us make sure that we are creating a Silverlight 5 application. After clicking the OK button in the New Project windows, a window will immediately be displayed to select the Silverlight version. So just select the Silverlight version 5.Out Of Browser Settings: Open the Project's property window and select Silverlight. Then follow the [No: #].The XAML:As we are creating the File Explorer, we need to spend time on designing the Screen. Initially the XAML page will have the default grid inside the user control. Let us add a TreeView control, ListBox and TextBox. TreeView: The above figure shows the TreeView structure. Here the ItemsSource is bound in code-behind. The ItemTemplate specifies how the items [Nodes] in the TreeView should be.ItemTemplate for TreeView:The snippet of ItemTemplate is given below. We might know that the Templates should be a UserControl Resource. This Item template is used to make the Nodes with Icon and Folder names.The [No: 1] specifies that the item collection is for sub-folders.In this stack panel, the image gives the icon and the text box is for the name of the folder.Loading Folders on Demand:If you ask "Is there any advantage of using this File Explorer", for this I can say that this File Explorer will load the folders on demand.Yes, this application will load the child folder ONLY when the parent folder is clicked. Once the folders have been loaded then it won't unload until you press the Refresh button. Quick Note:The Silverlight native TreeView does not have events for Expand and Collapse. So we are loading the folders in the SelectedItemChanged event of TreeView.When a folder is clicked we are also loading the files into the selected folder. To load the files from the selected folder we are using a ListBox in our application. Here in this figure above the ItemsSource is bound in code-behind.If you click on any of the files loaded you may see the content of the file that you selected but only if the file has one of the following extensions.The supported file extensions are:
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: