Hello All,
I want to access names of the files from the any folder in windows. I have used C# with silverlight and I tried to do following steps
page.xaml
<UserControl
xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="YetAnotherCarousel.Page"
>
<!--Width="1024" Height="768"-->
<Canvas x:Name="LayoutRoot" Background="Black" Width="1200" Height="800" >
</Canvas>
</UserControl>
page.xaml.cs
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.IO;
namespace YetAnotherCarousel
{
public partial class Page : UserControl
{
public Page()
{
// Required to initialize variables
InitializeComponent();
this.Loaded += new RoutedEventHandler(Page_Loaded);
}
private void CreateImage()
{
Carousel carousel = new Carousel();
Image[] imgObj = new Image[100];
int j = 1;
string[] fileEntries = Directory.GetFiles("D:/YetAnotherCarousel/YetAnotherCarousel/imges");
ERROR COMES HERE
foreach (string fileName in fileEntries)
{
Image imge = new Image();
imgObj[j] = imge;
imgObj[j].Source = new BitmapImage(new Uri(fileName, UriKind.Relative));
imgObj[j].Stretch = Stretch.Fill;
imgObj[j].Width = 400;
imgObj[j].Height = 300;
carousel.CreateItem(imgObj[j],fileName); // CreateItem is a separate function in Carousel.cs
j = j + 1;
}
this.LayoutRoot.Children.Add(carousel);
}
void Page_Loaded(object sender, RoutedEventArgs e)
{
CreateImage();
}
}
references mscorlib , system, system.core, system.Windows, system.windows.Browser, system.windows.controls.Extended, Sytem.xml.
Problem
So when I rebuild the solution it rebuilds successfully . But, when I run the program in browser it shows the error :::
( error locator symbol) / 4th row of createImage function
"MethodAccessException was unhandled by User Code"
"Attempt to access the method failed: System.IO.Directory.GetFiles(System.String)"
I have full access rights to my system. But, still I am unable to solve the problem.
Please help me. It really mkaing me mad. As I tried doing the same thing in normal c# and its running perfectly there but not running here in silverlight
Disclaimer:
PLEASE EXCUSE ME , if I asked some very basic thing , as I am new to Silverlight and trying my best to get the hands on this technology.
arpitgupta1@in.com
Arpit Gupta
Pune INDIA