The title may not be as clear so let me elaborate a little bit. I am creating an application that minifies CSS and JS files for web developers. All of the code is working perfectly except for one little pesky bug I can not figure out! Here is my code and then I will explain more about my issue:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ZippCast_Minify
{
public partial class Form1 : DevComponents.DotNetBar.Office2007Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void buttonX3_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "Select the File You Want to Minify";
ofd.Filter = "CSS Files (.css)|*.css|Javascript Files (.js)|*.js";
ofd.FilterIndex = 1;
DialogResult result = ofd.ShowDialog();
if (result == DialogResult.OK)
{
textBoxX1.Text = File.ReadAllText(ofd.FileName);
toolStripStatusLabel1.Text = "File Opened - " + ofd.FileName;
buttonX1.Enabled = true;
}
else
{
MessageBox.Show("Error: Please try again!", "Error Opening File", MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.Exit();
}
}
private void buttonX2_Click(object sender, EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Title = "Save the Minified Document";
sfd.Filter = "Minified CSS (*.min.css)|*.min.css|Minified Javascript (*.min.js)|*.min.js";
sfd.SupportMultiDottedExtensions = true;
DialogResult result = sfd.ShowDialog();
if (result == DialogResult.OK)
{
File.WriteAllText(sfd.FileName, textBoxX1.Text);
MessageBox.Show("Your file has been minified! You can find your file at:\n\n" + sfd.FileName, "File Minified Successfully", MessageBoxButtons.OK, MessageBoxIcon.Information);
buttonX1.Enabled = false;
buttonX2.Enabled = false;
buttonX3.Enabled = true;
toolStripStatusLabel1.Text = "File Opened - N/A";
textBoxX1.Text = "";
}
else
{
MessageBox.Show("Error: Please try again!", "Error Saving File", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonX1_Click(object sender, EventArgs e)
{
textBoxX1.Text = textBoxX1.Text.Replace(Environment.NewLine, "");
textBoxX1.Text = textBoxX1.Text.Replace(" ", "");
buttonX2.Enabled = true;
buttonX1.Enabled = false;
buttonX3.Enabled = false;
}
}
}
So, simple enough right? But when I am saving the document if I type in a file name and change the filter to the one I want to use, it inserts .min into the filename box as the extension. And if that wasn't bad enough, if you keep clicking them it will keep adding .min to the file. I am not sure why this is and any help would be awesome! Thanks guys!