Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
In the previous chapter in the series, I showed you how to create an out-of-browser app. Here, in this movie I want to concentrate on a special kind of OOB application known as an elevated trust application. At its simplest, it's just a matter of changing a configuration setting. Let me show you how. I'm inside Visual Studio and I've opened the CreateElevatedTrust project. Inside this application, I'm going to click on the Properties node in the Solution Explorer and show you, in this Silverlight section, that this is an out-of-browser application, and for debugging purposes, I'm telling it to dynamically generate a test page.
So, when I press F5, I see the standard out-of-browser experience. There is a web page. I can right-click and choose Install CreateElevatedTrust Application, I get the standard dialog with the standard logo, and if I click OK, it'll install it locally. Now, I want to make this an elevated trust application, so I go back to Visual Studio and I choose the Out-of-Browser Settings button and I simply check mark this Require elevated trust when running outside the browser.
While I'm in here, I can also change the default look of the window. I can add a no-border window or make it a borderless-round-corner window. I'll choose the Borderless Round Corners option and then click OK. Okay, now let's run the application again by pressing F5, and I'm going to right-click and choose Install, and you notice that the dialog is now a different color. It's not as friendly looking. It says, "The publisher could not be verified. Are you sure you want to install this application?" This is because the application has a higher risk factor and this yellow dialog is an attempt to alert the user that this is a potentially un-trusted application.
Now that the application has a higher trust level, we can do more with it. Let's install the application and see. There it is, now running out-of-browser, and notice that it no longer has a title bar across the top, and it's got the rounded borderless corners. Now, remove the application. Permanently remove it, say Yes, and then I'm going to turn back to Visual Studio, and I'm gong to write some code to allow me to access the user's music folder, now that I have some elevated privileges. While I'm back here in Visual Studio, I'm also going to take off the rounded corners.
I'm going to go back to the default look. I want to show the user a list of music files on my hard drive. Through the Open File dialog and the Save dialog classes, any Silverlight application can access the local file system. If I'm inside an elevated trust application then I get a little more privileges. It's possible for me to programmatically access file areas without the user interaction. So, I'm allowed to automatically parse the user folders, like My Documents, My Pictures, and My Music. I need to get some music in the Music folder.
So, let's go out to my hard drive. I'm going to go to my Desktop, find the exercise files folder, and I have a Music folder here, and I'm going to copy a couple of these files--number 4 and number 5--into my Music folder. There they are. And then I'm going to show those to my user in my Silverlight application. So, we'll return back to Visual Studio, I'll go to my code behind page on MainPage.xaml.cs by double-clicking, and I'm going to write some code here.
The first thing I'm going to do is check that I'm in an elevated privilege application. If I am, then I'm going to get a hold of the folder where my music files live. To do that, I'm going to create this variable called path and I'm going to go to my Silverlight application and say I want some information about my environments. I'm interested in getting a folder on the hard drive that is a special folder named My Music. What this will do when the application runs is it will find out who the user is on the local computer and find their specific music folder, wherever that lives.
And then I've got my ListBox, which I want to populate with this data. And to do that, I'm going to use the Directory class, which gives me access to the directories on the hard drive, and I'm going to call this function called EnumerateFiles. This lets me walk through all of the individual files that are inside that folder, and I tell it which folder I want by giving it the path. So, with these lines of code, I'm finding the local folder and passing that to EnumerateFiles. That's going to list all the files and then pass the list to the item source, and then the musicListBox will show them.
I'm going to put a break point right here by pressing F9, and then I'm going to run the application by pressing F5. I'm going to install the CreateElevatedTrust Application. I'll go through the yellow prompt, go ahead and click Install, and now I should be able to click on this Open Music List and as you can see, my music files show up. Success. This is great! You notice that I put a break point in my code. Normally, when you put a break point in your code that means that Visual Studio will stop there and let me examine my code and look at the variables and such.
That is not happening because I have to tell the debugger to attach to this process in a special way. Let me close this dialog, uninstall the application, choose Yes here. And then here's the key to debugging an elevated trust application. You need to go back to your Property section and find the Debug tab and choose Start Sction > Out-of-browser application. Now what happens when I press F5 is that it automatically installs the application and attaches the debugger now to the elevated trust app. And now you see I switch over to my code behind and I get the yellow arrow signifying that I'm stepping through the code.
I can then step through those lines of code and hover over this variable to see where the actual location is on my hard drive for that data. There's a lot more that you can do with an elevated trust application, as you'll find out in other movies in this chapter.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 98069 Viewers
61 Video lessons · 85308 Viewers
71 Video lessons · 69354 Viewers
56 Video lessons · 101717 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.