Silverlight IsolatedStorage PathTooLongException
Asked Answered
A

1

7

I'm getting this exception on 50% of WinXP SP3 machines. I know about 260 characters path length limit, but what can be done?

I'm already naming files to only 2 characters, without any subdirectories, but path to IsolatedStorage is already above 260 characters on half of WinXP machines.

Amabil answered 15/8, 2011 at 7:45 Comment(4)
Have you considered things like how long people's usernames are?Ferretti
@Tigran: One of reasons why it is so long is bacause I'm working in Russian Federation region, user profile path is much longer than on US machines, plus russian usernames tend to be longer than usual.Amabil
I wonder if IsolatedStorageSettings works? The 260 character limit is a limitation of the windows api so it's possible that not everything will run into the same problem? I suspect it won't work, but the only other suggestion I have is single character file names.Ferretti
Some APIs can accept more then 260, much more actually, but limitation also can be less then 260 characters. So if app going to "balance" on that edge, it's a good reason to begin to revise an architecture, cause may be now it works, but after some update it does't, or on some other machines it doesn't. So entire app become very fragile, which is not good.Ader
R
4

There ´s seems to be no real solution for this problem. The default path for the Isolated Storage under Windows XP is <SYSTEMDRIVE>\Documents and Settings\\Local Settings\Application Data\Microsoft\Silverlight\is on an english system, what is already really long. On MSDN is a good article about using Isolated Storage and Best Practises.

When you use isolated storage, following these guidelines will help you avoid problems and make the most of the protection isolated storage provides.

  • Wrap all calls to isolated storage within try/catch blocks to be resilient to potential IsolatedStorageExceptions, which can be thrown if isolated storage is
    disabled or if the store has been deleted.
  • If your Silverlight application needs to store a lot of data in isolated storage, consider hosting it on its own site so that it won't affect other applications on the site and other applications won't affect it.
  • If you have a group of Silverlight applications that need to share data on the client, host them on the same site.
  • Keep isolated storage paths as small as possible to prevent the internal full path from reaching the 260-character limit.
  • Encrypt sensitive data stored in isolated storage.
  • Use IsolatedStorageSettings to store objects and simple settings in isolated storage.
  • Use IsolatedStorageFile if you want to use file and stream-based APIs, are storing large amounts of data, or need fine-grained control over the contents of isolated storage.

To get around a PathToLongException you could check first the path of the IsolatedStorage and use an internal mapping to store your files in the IsolatedStorage. If the path to IsolatedStorage is too long by itself you should consider hosting the silverlight application on it´s own site and use IsolatedStorageFile.GetUserStoreForSite.

Rice answered 15/8, 2011 at 9:45 Comment(1)
Have you got some data to indicate the path is shorter for Site storage instead of Application storage? I don't see why it should be, looking at the directory structure used by IS.Cleome

© 2022 - 2024 — McMap. All rights reserved.