If you just open it for reading, you can do the following (assuming that you set the file assembly action to a resource):
System.IO.Stream myFileStream = Application.GetResourceStream(new Uri(@"/YOURASSEMBLY;component/xmlfiles/mensen.xml",UriKind.Relative)).Stream;
If you are trying to read / write this file, you will need to copy it to isolated storage. (Be sure to add using System.IO.IsolatedStorage )
You can use these methods for this:
private void CopyFromContentToStorage(String fileName) { IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication(); System.IO.Stream src = Application.GetResourceStream(new Uri(@"/YOURASSEMBLY;component/" + fileName,UriKind.Relative)).Stream; IsolatedStorageFileStream dest = new IsolatedStorageFileStream(fileName, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write, store); src.Position = 0; CopyStream(src, dest); dest.Flush(); dest.Close(); src.Close(); dest.Dispose(); } private static void CopyStream(System.IO.Stream input, IsolatedStorageFileStream output) { byte[] buffer = new byte[32768]; long TempPos = input.Position; int readCount; do { readCount = input.Read(buffer, 0, buffer.Length); if (readCount > 0) { output.Write(buffer, 0, readCount); } } while (readCount > 0); input.Position = TempPos; }
In both cases, make sure the file is set to Resource, and you will replace the YOURASSEMBLY part with the name of your assembly.
Using the methods above, to access your file, simply do the following:
IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication(); if (!store.FileExists(fileName)) { CopyFromContentToStorage(fileName); } store.OpenFile(fileName, System.IO.FileMode.Append);
source share