Silverlight: Getting the Parameters of a HTML Page PDF Print E-mail
Written by martcon   
Monday, 10 August 2009 13:11

To access the parameters passed to a HTML page that a Silverlight application is embedded in, you should use the QueryString method of the HTMLPage.Document class. For example, if the HTML Page URL is 'http://www.dummysite.com?username=myuser' you can access the username parameter as follows:

string username = HtmlPage.Document.QueryString["username"];

The value 'myuser' will be assigned to the above string. You must also import the following library to access the HTMLPage:

using System.Windows.WebBrowser;

For details on accessing parameters from within a HTML Page see http://tinyurl.com/786r4c.

 
Silverlight, PHP and the crossdomain.xml file PDF Print E-mail
Written by martcon   
Tuesday, 04 August 2009 08:48

One issue that we encountered when using Silverlight to access a PHP script deployed on an Apache Server relates to the use of clientaccesspolicy.xml and crossdomain.xml files. Officially, Silverlight first looks for a clientaccesspolicy.xml file and, if this isn't present, a crossdomain.xml file. However, when both files were present in the correct directory location we persistently got a 'System.Security.SecurityException' error. When we removed clientaccesspolicy.xml the Silverlight application connected with the PHP script. Thus, when connecting from Silverlight to PHP under an Apache Server, the rule of thumb would seem to be to use crossdomain.xml only.

For more details on clientaccesspolicy.xml and crossdomain.xml see http://tinyurl.com/njy2ox and http://tinyurl.com/m693n6.

 
Xampp, crossdomain.xml and clientaccesspolicy.xml PDF Print E-mail
Written by martcon   
Monday, 27 July 2009 11:35

Xampp (http://www.apachefriends.org/en/xampp.html) is Apache Server, PHP and MySQL in one package. It is easy to install and administer. One question that may arise if you are using a Rich Internet Application programming language such as Adobe Flex or Microsoft Silverlight is where to put your crossdomain.xml (used for Flex and, in certain instances, Silverlight) and/or clientaccesspolicy.xml file(used for Silverlight). Both must be put in the 'htdocs' directory. So if you've installed Xampp on the C: drive you must put your crossdomain.xml/clientaccesspolicy.xml file in the C:\xampp\htdocs directory.

The clientaccesspolicy.xml/crossdomain.xml file is required to enable a Rich Internet Application to access an application under a Web Server, for example, a PHP or Python script. If this file is in the incorrect location or not present at all you will encounter a security error such as the 'System.Security.SecurityException' in Silverlight.

 
Silverlight & PHP PDF Print E-mail
Written by martcon   
Thursday, 23 July 2009 10:44

PHP is a very popular language for accessing databases for Websites. It is only natural, therefore, that developers may wish to use Microsoft Silverlight to send data to a PHP script, perhaps for database addition, deletion or retrieval. You can use the C# WebClient class to connect to a PHP script for this purpose as follows:

// Test Variables for username and password.

string username="test";

string password = "mypassword";

// Set the Parameters for the PHP Script.

string parameters = String.Format("?username={0}&password={1}",username,password);

// Create a Web Client for contacting the PHP Script.

WebClient client = new WebClient();

// Call the PHP Script.

// Add the appropriate header.

client.Headers["Content-Type"] = "application/x-www-form-urlencoded";

// Add a callback handle for when the Save operation is completed.

client.UploadStringCompleted += new UploadStringCompletedEventHandler(LogonCompleted);

// Invoke the script and its parameters.

client.UploadStringAsync(new Uri("http://localhost/logonscript.php"+parameters,UriKind.Absolute),"POST");

In the above code we are calling a sample logon script called 'logonscript.php'. This dummy script takes a username and password as a parameter. In the sample code above, we first create variables for storing a username and password ('test' and 'mypassword') respectively. We then format these variables as parameters that the PHP script can read so they will appear to the PHP script as '?username=test&password=mypassword'.

We then create a Web Client, set a URL Encoded Header for this client and add an UploadStringCompletedEventHandler (as we are sending parameters to the script). We then invoke the UploadStringAsync method to call the script with its parameters. In our example we are using an absolute path (UriKind.Absolute) and we are posting data to the script as denoted by the "POST" parameter.

In the example the full path is 'http://localhost/logonscript.php?username=test&password=mypassword' where the dummy script name is 'logonscript.php'. This script would reside on a Web Server such as Apache or Microsoft IIS (Internet Information Services).

We referred to a callback handler above. Once the script has run this function is invoked to notify the Silverlight application that it is completed. An example implementation of this callback function is shown below:

private void LogonCompleted(Object sender, UploadStringCompletedEventArgs e)

{

            // We assume here that the script prints out "Success" or "Failure".

          if(e.Result.Equals("Success"))

         {

                   MessageBox.Show("Logon Succeeded");

          }

          else if(e.Result.Equals("Failure"))

        {

                 MessageBox.Show("Logon Failed");

         }

}

In this sample function the PHP script prints "Success" if the logon succeeded or "Failure" if the logon failed. This print out is stored in the Result member of event arguments parameter 'e'. We then check for these strings and display an appropriate message box.

The above example is for sending data to a PHP script. However, we can also retrieve data from a PHP script by print out the results and reading from the Result member of the events argument parameter 'e' in our callback function. Alternatively, if we are not sending parameters to the PHP script, we can use WebClient's DownloadStringAsync() method, set up a DownloadStringCompleted event and define a callback function with a signature similar to the following:

private void DownloadCompleted(Object sender, DownloadStringCompletedEventArgs e)

 
Multi-LineTextBoxes in Silverlight PDF Print E-mail
Written by martcon   
Monday, 13 July 2009 16:37

If you use Microsoft Silverlight for Web 2.0 UI Development you may wish to add a multi-line text box. To do this you use the AcceptsReturn property with the TextBox XAML Control:

<TextBox AcceptsReturn="True"></TextBox>

If you want horizontal or vertical scrollbars there are also properties available:

<TextBox AcceptsReturn="True" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"></TextBox>

Horizontal and vertical scrollbars appear automatically on the above multi-line text box. 

 
<< Start < Prev 1 2 3 4 5 6 7 8 9 10 Next > End >>

Page 10 of 19
RocketTheme Joomla Templates