Showing posts with label Silverlight. Show all posts
Showing posts with label Silverlight. Show all posts

Monday, April 18, 2011

Microsoft Silverlight hates Windows IE9

Tried IE9 64-bit. Found out that I'm running browser that not fully compatible with Microsoft Silverlight:


Go figure!

Wednesday, April 6, 2011

Delete directory in IsolatedStorage

IsolatedStorageFile.DeleteDirectory works with empty directories only.
I wrote the method for recursive deleting content of the directory:

using System.IO.IsolatedStorage;
. . .
        public void DeleteDirectory(IsolatedStorageFile fs, String dirName)
        {
            String pattern = dirName + @"\*";
            String[] files = fs.GetFileNames(pattern);
            foreach (String fName in files)
            {
                fs.DeleteFile(Path.Combine(dirName, fName));
            }
            String[] dirs = fs.GetDirectoryNames(pattern);
            foreach (String dName in dirs)
            {
                DeleteDirectory(fs, Path.Combine(dirName, dName));
            }
            fs.DeleteDirectory(dirName);
        }

Usage:
            using (IsolatedStorageFile fs = IsolatedStorageFile.GetUserStoreForApplication())
            {
                DeleteDirectory(fs, @"\Projects"); // directory "Projects" in the root will be deleted
            }


Wednesday, March 10, 2010

Silverlight: show image from database

            // image1 is Image SL control
            // blob is table entity
            // BLOBASIMAGE has type byte[] (db type: image)
            using (MemoryStream stream = new MemoryStream(blob.BLOBASIMAGE))
            {
                try
                {
                    BitmapImage im = new BitmapImage();
                    im.SetSource(stream);
                    image1.Stretch = Stretch.Uniform;
                    image1.Source = im;
                }
                catch (Exception)
                {   // major reason: wrong picture format. JPG is OK
                    image1.Source = null;
                }

            }