Friday 29 April 2011

Jeff Prosise's Blog : Silverlight 4's New Local File System Support and Problems with My Documents in Windows 7

While looking at the new restricted capabilities of Silverlight to deal with Files I came across this post Jeff Prosise's Blog : Silverlight 4's New Local File System Support. I downloaded the sample code an went to run it. It worked impressively in fact for the My Picture example. But I need to access folders in My Documents. So I tried that and oops it broke. The problem is that

string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

in windows 7 maps onto "C:\\Users\\name\\Documents" and the sub folders of that location have My Music, My Pictures and My Videos contained within and you cannot chain through these folders as you do not have permission to do so. So you have to skip over these thus

string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

foreach (string dir in Directory.EnumerateDirectories(path))
{
if (!dir.Contains("My Music") && !dir.Contains("My Pictures") && !dir.Contains("My Videos"))
etc

Another Gotcha in Windows 7 and file permissions is that if you download a zip file from the web is that certain files will be blocked and you have to unblock each one before you can process the files programmatically.

No comments:

Post a Comment