Me having a local xml file and need to load it to Isolated Storage when my app. starts for first time. but if i am opening that file using stream OR File.Open it's throwing an error. Also i need to store that file in serialized form. Please help, as being new to WP7 and C# not able to crack it.
Following code is used for opening the XML file:
FileStream stream = new FileStream("site.xml", FileMode.Open);
If the file is a part of your project then you can add the file to your project as resource. That means file "Build Action" of the file should be "Resource". And the following function can read the file from project resource.
Now you can read the stream according to the file type. If it is a XML file then you can read it like below.
As an example
How to write to isolated storage and read a file from isolated storage? Please check out the following link
http://www.codebadger.com/blog/post/2010/09/03/Using-Isolated-Storage-on-Windows-Phone-7.aspx
Also you can checkout the link below regarding Local Data Storage for Windows Phone.
http://msdn.microsoft.com/en-us/library/ff626522%28v=vs.92%29.aspx
You need to specify the FileAccess mode as well for any Content type resource, since you can't open it in write-mode.
Try change your code to:
Also, see this question: How to fix exception MethodAccessException during file reading?