Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/257.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# 将值与以下值进行比较: thisDialog.InitialDirectory = Settings.Default.LastPath;_C#_Winforms - Fatal编程技术网

C# 将值与以下值进行比较: thisDialog.InitialDirectory = Settings.Default.LastPath;

C# 将值与以下值进行比较: thisDialog.InitialDirectory = Settings.Default.LastPath;,c#,winforms,C#,Winforms,删除这一行,就有了最后一条路径 thisDialog.InitialDirectory = "c:\\"; 删除这一行,就有了最后一条路径 thisDialog.InitialDirectory = "c:\\"; 你能给我看看我的代码的例子放在哪里吗?(它对我不起作用)你能给我看一下我的代码的例子放在哪里吗?(这对我不起作用) if(thisDialog.Filenames.Length > 0) _lastPath = Path.GetDirectoryName(thisD

删除这一行,就有了最后一条路径

thisDialog.InitialDirectory = "c:\\";

删除这一行,就有了最后一条路径

thisDialog.InitialDirectory = "c:\\";

你能给我看看我的代码的例子放在哪里吗?(它对我不起作用)你能给我看一下我的代码的例子放在哪里吗?(这对我不起作用)
if(thisDialog.Filenames.Length > 0)
    _lastPath = Path.GetDirectoryName(thisDialog.Filenames[0]);
thisDialog.InitialDirectory = (_lastPath.Length > 0 ? _lastPath: "c:\\"); 
// This at the global level of your form 
private string _lastPath = string.Empty;**

private void btnAdd_Click(object sender, EventArgs e) 
{ 
    System.IO.Stream myStream; 
    OpenFileDialog thisDialog = new OpenFileDialog(); 
    thisDialog.InitialDirectory = (_lastPath.Length > 0 ? _lastPath: "c:\\");
    thisDialog.Filter = "(*.snoop, *.pcap, *.cap, *.net)|*.snoop; *.pcap; *.cap; *.net|" + "All files (*.*)|*.*"; 
    thisDialog.FilterIndex = 1; 
    thisDialog.RestoreDirectory = false; 
    thisDialog.Multiselect = true; // Allow the user to select multiple files 
    thisDialog.Title = "Please Select Source File"; 
    thisDialog.FileName = lastPath; 
    List<string> list = new List<string>(); 

    if (thisDialog.ShowDialog() == DialogResult.OK) 
    { 
        if(thisDialog.Filenames.Length > 0) 
            _lastPath = Path.GetDirectoryName(thisDialog.Filenames[0]);

        foreach (String file in thisDialog.FileNames) 
        { 
            try 
            { 
                if ((myStream = thisDialog.OpenFile()) != null) 
                { 
                    using (myStream) 
                    { 
                        listBoxFiles.Items.Add(file); 
                    } 
                } 
            } 

            catch (Exception ex) 
            { 
                MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message); 
            } 
        } 

    } 
} 
Settings.Default.LastPath = LastPathSelected;
thisDialog.InitialDirectory = Settings.Default.LastPath;
thisDialog.InitialDirectory = "c:\\";