save files in local storage

Dec 5 2017 1:46 AM
hey team,
 
I just added two text boxes which is in a read only thing.Beside the textboxex i have kept the buttons called browse which shall be useful to browse a file from the directory and display it in a text box. Also i have kept a generate button which should again save the displayed files in the local storage but i could not proceed with it. Do solve my issue in a detailed manner.
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
//using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace gui_1
{
public partial class form1 : Form
{
public form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\";
openFileDialog1.Filter = "xlsx files (*.xlsx)|*.xlsx";
openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string text = openFileDialog1.SafeFileName;
if (text == "Book1.xlsx")
{
tb_1.Text = openFileDialog1.FileName;
}
else
{
MessageBox.Show("Invalid file name");
tb_1.Clear();
}
}
}
private void label1_Click(object sender, EventArgs e)
{
}
private void fn_l2_Click(object sender, EventArgs e)
{
}
public static void SaveData(object obj, string filename)
{
}
private void browse_b2_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\";
openFileDialog1.Filter = "xlsx files (*.xlsx)|*.xlsx";
openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string text = openFileDialog1.SafeFileName;
if (text == "Book2.xlsx")
{
tb_2.Text = openFileDialog1.FileName;
}
else
{
MessageBox.Show("Invalid file name");
tb_2.Clear();
}
}
}
private void tb_1_TextChanged(object sender, EventArgs e)
{
}
private void cancel_b1_Click(object sender, EventArgs e)
{
this.Close();
}
private void reset_b1_Click(object sender, EventArgs e)
{
Utilities.ResetAllControls(this);
}
public class Utilities
{
public static void ResetAllControls(Control form)
{
foreach (Control control in form.Controls)
{
if (control is TextBox)
{
TextBox textBox = (TextBox)control;
textBox.Text = null;
}
}
}
}
private void generate_b1_Click(object sender, EventArgs e)
{
if (tb_1.Text == "")
MessageBox.Show("Fields are empty!!");
if (tb_2.Text == "")
MessageBox.Show("Fields are empty!!");
}
}
}

Answers (1)