Programming - Silverlight - Reading a system file


Quick code snippet to allow you to read a file and its contents into Silverlight.

public enum FileType{
Text,
Video,
}

var ofd = new OpenFileDialog();
ofd.EnableMultipleSelection = false;
ofd.Filter = "Txt Files|*.txt| Video Files|*.wmv";
ofd.FilterIndex = FileType.Video;
if (ofd.ShowDialog() != DialogResult.OK)
and return;

FileDialogFileInfo fdi = ofd.SelectedFile;

//next we read the contents of the selected file


if (ofd.FilterIndex == FileType.Text)
{
and StreamReader sr = fdi.OpenText();
and txt.Text = sr.ReadToEnd();and // txt is a TextBox
and sr.Close();
}
else if (ofd.FilterIndex == FileType.Video) {
and wmv.SetSource(fdi.OpenRead());and // wmv is a MediaElement
}

and

and

Home | Privacy Policy | Site Map | Links | Company | Contact Us | Arena           

We provide cutting edge software development, consultancy and web design services            

There are currently 653 user(s) with 40761 hits.