CodeTV.PanelChannel.insertChannelsToolStripMenuItem_Click C# (CSharp) Method

insertChannelsToolStripMenuItem_Click() private method

private insertChannelsToolStripMenuItem_Click ( object sender, EventArgs e ) : void
sender object
e System.EventArgs
return void
        private void insertChannelsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.InitialDirectory = this.GetType().Module.FullyQualifiedName;
            openFileDialog.Filter = Properties.Resources.ChannelXMLFilter;
            openFileDialog.FilterIndex = 2;
            openFileDialog.RestoreDirectory = true;
            openFileDialog.FileName = MainForm.AssemblyName + ".Channels.xml";
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                Stream fileStream = null;
                try
                {
                    if ((fileStream = openFileDialog.OpenFile()) != null)
                    {
                        ChannelFolder parentChannel = MainForm.rootChannelFolder;
                        TreeNodeCollection parentTreeNodeCollection = this.treeViewChannel.Nodes;
                        if (this.treeViewChannel.SelectedNode != null)
                        {
                            if (this.treeViewChannel.SelectedNode.Tag is ChannelFolder)
                            {
                                parentChannel = this.treeViewChannel.SelectedNode.Tag as ChannelFolder;
                                parentTreeNodeCollection = this.treeViewChannel.SelectedNode.Nodes;
                            }
                            else
                            {
                                if (this.treeViewChannel.SelectedNode.Parent != null)
                                {
                                    parentChannel = this.treeViewChannel.SelectedNode.Parent.Tag as ChannelFolder;
                                    parentTreeNodeCollection = this.treeViewChannel.SelectedNode.Parent.Nodes;
                                }
                            }
                        }
                        InsertChannels(fileStream, parentChannel, parentTreeNodeCollection);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                finally
                {
                    if (fileStream != null)
                        fileStream.Close();
                }
            }
        }