Freigeben über


How to: Use OpenFileDialog on Nokia S60

Microsoft Silverlight will reach end of support after October 2021. Learn more.

The OpenFileDialog class is customized to support media scenarios on Nokia S60 devices, such as playing audio and video, creating videos , and taking pictures from the phone camera and sharing them with friends or family by using popular social networking websites.

On Nokia S60, the OpenFileDialog class automatically searches for media files on the phone (in phone memory, mass memory, and media storage) and presents the user with a thumbnail preview of the media for easy identification.

You can specify a file filter so that only photos or videos are displayed. If no filter is specified, photos are displayed by default.

To upload the selected file to a web server, use WebClient or a similar Silverlight type. The upload of multiple files in a single call is not supported.

The Filter property gets or sets the filter string that determines which file types are displayed in OpenFileDialog. The implementation of the Filter property on Nokia S60 differs from its implementation on Silverlight 2 in the following ways:

  • The default return type is String.Empty, which means that no filter is applied and all photos are displayed.

  • Setting a filter value of *.mp4 displays all video files, regardless of the extension.

  • Setting multiple filter values is not supported. For example, the following code is not supported.

    Label|Extension1[[;Extension2]...[;ExtensionN]]
    
NoteNote:

The set operation for the FilterIndex property is unsupported. If it is used, the new value is ignored. The default return value is 1.

Example

The following example shows how to enable simple file selection by using OpenFileDialog. It also shows how to enable file upload by using WebClient.

public void SelectAndUpload()
{
    OpenFileDialog dlg = new OpenFileDialog();
    bool? retval = dlg.ShowDialog();
    
    if (retval != null && retval == true)
    {
        UriBuilder ub = new
            UriBuilder("https://localhost/receiver.ashx");
        ub.Query = string.Format("filename={0}", dlg.File.Name);
        WebClient c = new WebClient();
        c.OpenWriteCompleted += (sender, e) =>
        {
            UploadData(data, e.Result);
            e.Result.Close();
            data.Close();
        };
        c.OpenWriteAsync(ub.Uri);
    }
}
private void UploadData(Stream input, Stream output)
{
    byte[] buffer = new byte[4096];
    int bytesRead;

    while ((bytesRead = input.Read(buffer, 0, buffer.Length)) != 0)
    {
        output.Write(buffer, 0, bytesRead);
    }
}

See Also

Concepts