Beispiel #1
0
        private void buttonLoadFIle_Click(object sender, EventArgs e)
        {
            if (buttonLoadFIle.Text == "Load File")
            {
                DialogResult result = openFileDialog.ShowDialog();
                fileLoc = openFileDialog.FileName;
                if (result == DialogResult.OK) // Test result.
                {
                    string ext = Path.GetExtension(openFileDialog.FileName);
                    if (ext == ".xml")
                    {
                        labelFile.Text = fileLoc;
                        string xmlRawText = string.Empty;
                        try
                        {
                            try
                            {
                                textBoxSource.Text      = XmlOperation.LoadFileToXML(fileLoc, out newDocument);
                                textBoxSource.ForeColor = Color.Black;
                                buttonLoadFIle.Text     = "UnLoad File";
                                fileLoadStatus          = true;
                            }
                            catch { }
                        }
                        catch
                        {
                            textBoxSource.Text      = xmlRawText;
                            textBoxSource.ForeColor = Color.Red;
                        }
                    }
                    else
                    {
                        UtilityOperations.ShowMessageBox("File Format Not Supported. (I.E. .XML or .TXT)", MessageBoxIcon.Error);
                    }

                    if (ext == ".xml")
                    {
                        textBoxElement.Enabled = true;
                    }
                    else
                    {
                        textBoxElement.Enabled = false;
                    }
                }
            }
            else
            {
                buttonLoadFIle.Text    = "Load File";
                labelFile.Text         = "File Location";
                fileLoadStatus         = false;
                textBoxSource.Text     = "";
                textBoxElement.Enabled = true;
            }
        }
Beispiel #2
0
        private void buttonLoadXML_Click(object sender, EventArgs e)
        {
            DialogResult result = openFileDialogXML.ShowDialog();

            fileLoc = openFileDialogXML.FileName;
            if (result == DialogResult.OK) // Test result.
            {
                toolStripStatusLabelStatus.Text = "Status";
                textBoxDestination.Text         = "";
                labelFile.Text = fileLoc;
                if (fileLoc.Contains(".txt"))
                {
                    try
                    {
                        string fileContent = File.ReadAllText(fileLoc);
                        textBoxSource.Text = fileContent;
                    }
                    catch
                    {
                        MessageBox.Show("Can not load the file.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
                    }
                }
                else if (fileLoc.Contains(".xml"))
                {
                    string xmlRawText = string.Empty;
                    try
                    {
                        try
                        {
                            textBoxSource.Text      = XmlOperation.LoadFileToXML(fileLoc, out newDocument);
                            textBoxSource.ForeColor = Color.Black;
                        }
                        catch { }
                    }
                    catch
                    {
                        textBoxSource.Text      = xmlRawText;
                        textBoxSource.ForeColor = Color.Red;
                    }
                }
                else
                {
                    MessageBox.Show("File format not supported. Please upload XML or TXT file.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
                }
            }
        }