Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从“复制文件”;“源代码目录”;隔离存储_C#_Windows Phone 8_Isolatedstorage - Fatal编程技术网

C# 从“复制文件”;“源代码目录”;隔离存储

C# 从“复制文件”;“源代码目录”;隔离存储,c#,windows-phone-8,isolatedstorage,C#,Windows Phone 8,Isolatedstorage,我已经创建了一些sqlite数据库,并将其放在我的项目内容中 如何检查用户首次安装应用程序并将这2个数据库复制到独立存储中 我尝试过这种方法,但它给了我一个错误“对象引用未设置为对象的实例。”在第行 using (Stream stream = Application.GetResourceStream(new Uri("/Assets/DBS/MyPlaylist.db", UriKind.Relative)).Stream) 这是我的密码 private static string D

我已经创建了一些sqlite数据库,并将其放在我的项目内容中

如何检查用户首次安装应用程序并将这2个数据库复制到独立存储中


我尝试过这种方法,但它给了我一个错误
“对象引用未设置为对象的实例。”
在第行

using (Stream stream = Application.GetResourceStream(new Uri("/Assets/DBS/MyPlaylist.db", UriKind.Relative)).Stream)
这是我的密码

private static string DataFolder = "Datas";      
public static void FirstTimeCopyDB()
    {
        using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
        {
            if (!isf.DirectoryExists(DataFolder)) 
            {
                isf.CreateDirectory(DataFolder);  
                using (Stream stream = Application.GetResourceStream(new Uri("/Assets/DBS/MyPlaylist.db", UriKind.Relative)).Stream)
                {
                    using (IsolatedStorageFileStream isfs = isf.CreateFile("Datas/MyPlaylist.db"))
                    {
                        byte[] buffer = new byte[1024];
                        int byteRead = -1;
                        while ((byteRead = stream.Read(buffer, 0, buffer.Length)) > 0)
                        {
                            isfs.Write(buffer, 0, byteRead);
                        }
                    }
                }
                using (Stream stream = Application.GetResourceStream(new Uri("/Assets/DBS/MyDatabase.db",UriKind.Relative)).Stream)
                {
                    using (IsolatedStorageFileStream isfs = isf.CreateFile("Datas/MyDatabase.db"))
                    {
                        byte[] buffer = new byte[1024];
                        int byteRead = -1;
                        while ((byteRead = stream.Read(buffer,0,buffer.Length))>0)
                        {
                            isfs.Write(buffer,0,byteRead);
                        }
                    }
                }
            }
            else return;
        }
    }
大概是这样的:

using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
    if (!store.FileExists("yourDBfileName")) 
    {
     // copy yourDBfile 
    }
}

探索更多内容

在复制之前,只需检查数据库文件是否存在于隔离存储中我添加了一些信息,希望您能帮助我:好的,我发现我必须向路径添加一些头,现在它工作了:)
使用(Stream Stream=Application.GetResourceStream(新Uri(“phone_mp3;component/Assets/DBS/MyPlaylist.DB”),UriKind.Relative)).Stream)