Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.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
检查内存WP7中是否存在xml文件_Xml_Windows Phone 7_Isolatedstoragefile - Fatal编程技术网

检查内存WP7中是否存在xml文件

检查内存WP7中是否存在xml文件,xml,windows-phone-7,isolatedstoragefile,Xml,Windows Phone 7,Isolatedstoragefile,我将一个xml文件从互联网下载到手机内存中。。我想看看是否可以通过internet连接进行下载,如果不能,则发送消息。如果没有,我想看看xml文件是否已经存在于内存中。。如果存在,应用程序不会进行下载 问题是我不知道如何设置if条件来查看文件是否存在 我有以下代码: public MainPage() { public MainPage() { if (NetworkInterface.GetIsNetworkAvailable()) {

我将一个xml文件从互联网下载到手机内存中。。我想看看是否可以通过internet连接进行下载,如果不能,则发送消息。如果没有,我想看看xml文件是否已经存在于内存中。。如果存在,应用程序不会进行下载

问题是我不知道如何设置if条件来查看文件是否存在

我有以下代码:

public MainPage()
{
    public MainPage()
    {
        if (NetworkInterface.GetIsNetworkAvailable())
        {
            InitializeComponent();

            WebClient downloader = new WebClient();
            Uri xmlUri = new Uri("http://dl.dropbox.com/u/32613258/file_xml.xml", UriKind.Absolute);
            downloader.DownloadStringCompleted += new DownloadStringCompletedEventHandler(Downloaded);
            downloader.DownloadStringAsync(xmlUri);
        }
        else
        {
            MessageBox.Show("The internet connection is not available");
        }
    }

    void Downloaded(object sender, DownloadStringCompletedEventArgs e)
    {
        if (e.Result == null || e.Error != null)
        {
            MessageBox.Show("There was an error downloading the xml-file");
        }
        else
        {
            IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();
            var stream = new IsolatedStorageFileStream("xml_file.xml", FileMode.Create, FileAccess.Write, myIsolatedStorage);
            using (StreamWriter writeFile = new StreamWriter(stream))
            {
                string xml_file = e.Result.ToString();
                writeFile.WriteLine(xml_file);
                writeFile.Close();
            }
        }
    }
}

我不知道如何查看文件是否存在条件:

IsolatedStorageFile类有一个名为FileExists的方法。见 如果只想检查文件名,也可以使用GetFileNames方法,该方法提供IsolatedStorage根目录中文件的文件名列表


我不能保证上面的代码能够准确地工作,但这是如何进行的一般思路。

IsolatedStorageFile类有一个名为FileExists的方法。见 如果只想检查文件名,也可以使用GetFileNames方法,该方法提供IsolatedStorage根目录中文件的文件名列表


我不能保证上面的代码能够准确地工作,但这是如何进行的一般思路。

但是我在这种情况下会做什么?我不明白:ifgetfilename.xml_file=true?????另外,我不确定foreach是否可以使用字符串数组。试试通常的for循环。但是在这种情况下我会怎么做呢?我不明白:ifgetfilename.xml_file=true?????另外,我不确定foreach是否可以使用字符串数组。试试通常的for循环。
IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();
if(myIsolatedStorage.FileExists("yourxmlfile.xml))
{
    // do this
}
else
{
    // do that
}
IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();
string[] fileNames = myIsolatedStorage.GetFileNames("*.xml")
foreach (string fileName in fileNames)
{
    if(fileName == "yourxmlfile.xml")
    {
      // do this
    }
    else
    {
      // do that
    }
}