0

I have a problem with displaying videos in a grid using <MediaElement>. I have made a separate class to get the video details with get set properties. Problem is i can't access the videos folder on window load when i debug the program. I have saved a folder named Videos in debug folder as well. If any one can help!! Thanks in advance.

VideoDetail.cs

public string Name { get; set; }
public string Description { get; set; }
public string Path { get; set; }
public string FileName { get; set; }
public string Extension { get; set; }
public int Height { get; set; }
public int Width { get; set; }
public long Size { get; set; }

Window.xaml

<ItemsControl Name="VideoList" ItemsSource="{Binding VideoList}">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <Border BorderThickness="1" BorderBrush="#FFD0D1D7" Padding="5" Margin="10,10,0,0">
                <StackPanel Orientation="Horizontal">
                    <!--image -->
                    <Grid Width="200" Height="150">
                        <MediaElement Source="{Binding Path}"/>
                    </Grid>
                </StackPanel>
            </Border>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

Window.xaml.cs

private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        string root = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
        string[] supportedExtensions = new[] { ".mp4" };
        var files = Directory.GetFiles(Path.Combine(root, "Videos"), "*.*").Where(s => supportedExtensions.Contains(Path.GetExtension(s).ToLower()));

        List<ImageDetails> videos = new List<ImageDetails>();

        foreach (var file in files)
        {
        ImageDetails id = new ImageDetails()
            {
                Path = file,
                FileName = Path.GetFileName(file),
                Extension = Path.GetExtension(file)
            };

        FileInfo fi = new FileInfo(file);
            id.Size = fi.Length;
            videos.Add(id);
        }

       VideoList.ItemsSource = videos;
    }
}
tabia
  • 55
  • 1
  • 6
  • 1
    I think you're using the wrong method to locate your program folder. There are a number of alternate suggestions here: http://stackoverflow.com/questions/52797/how-do-i-get-the-path-of-the-assembly-the-code-is-in . – goobering Aug 31 '15 at 17:39
  • and what if i want to access the folder in project not in debug folder? – tabia Aug 31 '15 at 17:43
  • well i have done it simply giving the root path directly :) thanks for the help – tabia Aug 31 '15 at 17:54

0 Answers0