my app has a function to read file names and display them in the first column one by one in the DataGridView. What I want to do is, if users type in new names in the second column next to its original name, and then press the 'save as' button, files get saved consequently as newly typed in names, according to the order of the list.
I didn't bind it with DB or something like that.
My guess is that if users click save as button, it calls the code of each newly named block, and bring that code to 'save as' function. But I have no idea how I could realize it. Maybe my guess is totally wrong; you could give some advice so that I can find a right way!
I kindly ask for you help!
Here's my code
private void button2_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Word(*.docx)| *.docx|PPT(*.pptx)|*.pptx|PDF(*.pdf)|*.pdf|Alle Dateien(*.*)|*.*";
ofd.Multiselect = true;
string ndn = "";//neue Dateinamen
bool umlaut, pdf, wasserzeichen;
int kopien;
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string[] selectedFiles = ofd.SafeFileNames;
for (int i = 0; i < ofd.FileNames.Count() - 1; i++)
{
dataGridView1.Rows.Add(selectedFiles[i]);
dataGridView1.Rows[i].Cells["Dateinamen"].Value.ToString();
dataGridView1.Rows[i].Cells["Neue Dateinamen"].Value.ToString(); // Here I tried to save values of new names
dataGridView1.Rows[i].Cells["Kopien"].Value.ToString();
dataGridView1.Rows[i].Cells["Wasserzeichen"].Value.ToString();
dataGridView1.Rows[i].Cells["Umlaut"].Value.ToString();
dataGridView1.Rows[i].Cells["PDF"].Value.ToString();
}
}
private void button7_Click(object sender, EventArgs e) //Save as
{
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "Word(*.docx)| *.docx|PPT(*.pptx)|*.pptx|PDF(*.pdf)|*.pdf|Alle Dateien(*.*)|*.*";
saveFileDialog1.RestoreDirectory = true;
saveFileDialog1.CheckFileExists = true;
saveFileDialog1.CheckPathExists = true;
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
}
}
}
}
Try the following code for the save button
The variable FilesPath is a public string. This variable will contain the directory name where your selected files are. Look an example of the code for the button that reads the file list
There you can see the line where the variable FilesPath is filled.