New Features of Silverlight 5 beta: 10. Creating TXT text files in HTML + browser mode in browser Mode

Source: Internet
Author: User

In Silverlight 5 beta, you can use the webbrowser control in browser mode to access webpages and create TXT text files in browser mode. Of course, to obtain this function, there are three conditions to add a new key in the registry and set the xap signature (if it is in the local http: // localhost: these two conditions are not required during the test) and enhance the trust level.

First, add a new key allowelevatedtrustappsinbrowser to the Registry.

Its name is allowelevatedtrustappsinbrowser, which is of the DWORD type and the value is 1. Set Silverlight to allow access to some local resources.

 
• Key name: allowelevatedtrustappsinbrowser
• Key type: DWORD
• Key value:Zero X 00000000(Disabled) orZero X 00000001(Enabled)

The key registration location is different in 32-bit and 64-bit systems. For details, see:


   
  
  • HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Silverlight \(For 32-bit) or
  • HKEY_LOCAL_MACHINE \ SOFTWARE \ wow6432node \ Microsoft \ Silverlight(For 64-bit)

2. Setting the xap package signature is a trusted application.Program

1. Right-click the Silverlight project --> properties --> signature --> click "sign xap file" --> click "create test certificate ". As shown in:

 

2. Install the certificate: click "More details"> "Install certificate (I)" in )". For example:

3. in the pop-up "Certificate import wizard" window, select "put all certificates in the following storage areas" -- in the pop-up "select certificate storage" window, select a trusted root certificate authority ". For example:

4. The signature certificate is successfully installed.

Iii. enhance trust level

First, we set the OOB mode of Silverlight to improve the trust level as follows:

Here we have upgraded the OOB mode trust level. At this time, the project will automatically set to start from the Silverlight project, as shown in the left figure. We need to manually set to start from the web project, as shown in the right figure:

Let's take a look at this article.ArticleInstance demoCodeThe mainpage. XAML code is as follows:

<Grid X: Name = "layoutroot" background = "white"> <webbrowser Height = "463" horizontalalignment = "Left" margin = "0,137, 800 "name =" webbrowser1 "verticalignment =" TOP "width =" "/> <button content =" loading Baidu "Height =" 39 "horizontalalignment =" Left "margin =" 25, 58, 0, 0 "name =" button1 "verticalignment =" TOP "width =" 141 "Click =" button#click "/> <button content =" Open wordbook "Height =" 39 "horizontalalignment =" left "margin =" 314,58, 141 "name =" button2 "verticalignment =" TOP "width =" "Click =" button2_click "/> <button content =" Create File "Height =" 39 "horizontalalignment =" left "margin =" 626,58, 141 "name =" button3 "verticalignment =" TOP "width =" "Click =" button3_click "/> </GRID>

Next we will look at the CS Code as follows:

  Private     Void  Button#click (  Object  Sender, routedeventargs E)
{
// Access Baidu
This . Webbrowser1.source = New Uri ( " Http://www.baidu.com/ " ,
Urikind. relativeorabsolute );
}

Private Void Button2_click ( Object Sender, routedeventargs E)
{
// Open a notepad File
Dynamic cmd = Automationfactory. Createobject ( " Wscript. Shell " );
Cmd. Run ( @" C: \ windows \ notepad.exe " , 1 , True );
}
Random _ RND = New Random ();
Private Void Button3_click ( Object Sender, routedeventargs E)
{
// Create a file storage path
VaR tempdirectory = @" C: \ Temp " ;
If ( ! Directory. exists (tempdirectory ))
{
Directory. createdirectory (tempdirectory );
}

// Full name of the created File
VaR filename = String . Format ( " Tempfile-000002.16.txt " , _ RND. Next ( 0 , 65536 ));
VaR fullpath = System. Io. Path. Combine (tempdirectory, filename );

// Write a new file
Using (Filestream FS = File. Create (fullpath ))
Using (Streamwriter SR = New Streamwriter (FS, encoding. utf8 ))
{
Sr. writeline ( " This is a trusted xap file. " );
}

// Notify users
MessageBox. Show ( " File Created successfully " );

}

Finally, let's take a look at the effect of clicking the three buttons, as shown in the following three figures:

This example is written in vs2010 + Silverlight 5 beta. If you need the source code, click sl5trusted.zip to download it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.