문제

I'm trying to write a string to an IsolatedStorageFile, but I'm getting an IsolatedStorageException, the link in the exception is this one:

http://www.microsoft.com/getsilverlight/DllResourceIDs/Default.aspx?Version=4.0.50829.0&File=mscorlib.dll&Key=IsolatedStorage_Operation_ISFS

And it states that the definition of 'resource ID' could not be found. I have no idea why this exception occurs, here's my code:

private void writeListToStorage(List<PlanningItemModel> items)
    {
        IsolatedStorageFile myIsolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication();
        if(myIsolatedStorageFile.FileExists("Zomerparkfeesten\\" + filePath))
        {
            IsolatedStorageFileStream iStream = myIsolatedStorageFile.OpenFile("Zomerparkfeesten\\" + filePath, FileMode.Open, FileAccess.Write);
            string json = Converter.convertListOfItemsToJson(items);
            StreamWriter writeFile = new StreamWriter(iStream);
            try
            {
                writeFile.WriteLine(json);
                writeFile.Close();
                iStream.Close();
            }
            catch (IOException)
            {
                writeFile.Close();
                iStream.Close();
            }
        }
        else 
        {
            myIsolatedStorageFile.CreateFile("Zomerparkfeesten\\" + filePath);
            this.writeListToStorage(items);
        }
    }

Any ideas?

도움이 되었습니까?

해결책

And it states that the definition of 'resource ID' could not be found

No, that's not what it says. Odd problem, might have something to do with you speaking Dutch instead of English. Looks like they fumbled the Dutch localization of this particular exception. When I visit that URL from the USA, I get:

Operation not permitted on IsolatedStorageFileStream

Which of course makes a lot more sense, given the code snippet. I can't get you a lot more help beyond that, basic issue is that your program doesn't have write access to isolated storage. You'll need to give it access.

One nasty failure mode that's hard to diagnose, this code will always blow up with "Operation not permitted" when you pass an empty string for "filePath". That will make the code try to write a file that has the same name as an existing directory, that's never permitted.

다른 팁

Try to use this code:

 using (IsolatedStorageFile myIsolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (!myIsolatedStorageFile.DirectoryExists("Zomerparkfeesten"))
                {
                    myIsolatedStorageFile.CreateDirectory("Zomerparkfeesten");
                    myIsolatedStorageFile.CreateFile("Zomerparkfeesten//" + filePath);

                }
                else
                {
                    if (!myIsolatedStorageFile.FileExists("Zomerparkfeesten//" + filePath))
                    {
                        myIsolatedStorageFile.CreateFile("Zomerparkfeesten//" + filePath);
                    }

                }

                using (Stream stream = new IsolatedStorageFileStream("Zomerparkfeesten//" + filePath, FileMode.Append, FileAccess.Write, myIsolatedStorageFile))
                {
                    using (StreamWriter writer = new StreamWriter(stream))
                    {
                        writer.WriteLine("Test");// some your data
                        writer.Close();
                        stream.Close();
                    }
                }

            }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top