folderBrowserDialog and Saving file
-
Hi Guys. I have just spent about 5 hours searching the web trying to find a solution to my problem. I am busy with a project where I am writing data to an Excel file. This works fine. I then want to save the Excel file to a pre-selected directory which the user select using the folderBrowserDialog. Now, I need to know how do I then save my file to the directry selected. I am displaying the Selected path in a txtbox. I only want to save the file to this directory. follderBrowserDialog code:
private void btSelectDirToSave\_Click(object sender, EventArgs e) { if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { txtboxSelectExcelDir.Text = folderBrowserDialog1.SelectedPath; } }
File save code:
string namefile; namefile = txtboxSelectExcelDir.Text; objExcel.ActiveWorkbook.SaveAs(namefile + "\_Nom022.xls",Excel.XlFileFormat.xlWorkbookNormal,Type.Missing,Type.Missing,Type.Missing, Type.Missing,Excel.XlSaveAsAccessMode.xlNoChange,Type.Missing,Type.Missing,Type.Missing,Type.Missing);
Any Help would be greatly appreciated as the file is currently not being saved to the selected directory but the Directory name is appended to the filename and saved somewhere else. :( :sigh: :(
Excellence is doing ordinary things extraordinarily well.
-
Hi Guys. I have just spent about 5 hours searching the web trying to find a solution to my problem. I am busy with a project where I am writing data to an Excel file. This works fine. I then want to save the Excel file to a pre-selected directory which the user select using the folderBrowserDialog. Now, I need to know how do I then save my file to the directry selected. I am displaying the Selected path in a txtbox. I only want to save the file to this directory. follderBrowserDialog code:
private void btSelectDirToSave\_Click(object sender, EventArgs e) { if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { txtboxSelectExcelDir.Text = folderBrowserDialog1.SelectedPath; } }
File save code:
string namefile; namefile = txtboxSelectExcelDir.Text; objExcel.ActiveWorkbook.SaveAs(namefile + "\_Nom022.xls",Excel.XlFileFormat.xlWorkbookNormal,Type.Missing,Type.Missing,Type.Missing, Type.Missing,Excel.XlSaveAsAccessMode.xlNoChange,Type.Missing,Type.Missing,Type.Missing,Type.Missing);
Any Help would be greatly appreciated as the file is currently not being saved to the selected directory but the Directory name is appended to the filename and saved somewhere else. :( :sigh: :(
Excellence is doing ordinary things extraordinarily well.
use this method i find it easier
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { txtboxSelectExcelDir.Text = folderBrowserDialog1.FileName; }
// Then saving it as a .txt is what i do... :)
// Get the info seperated by tabs
String info = String.Empty;
using (StreamWriter sw = File.CreateText(folderBrowserDialog1.FileName)
{
sw.Write(//whatever info here);Make sure the info is seperated by tabs, to indicate different cells for example,
col1, row1\tcol2, row1\r\ncol1, row2\tcol2, row2
-
use this method i find it easier
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { txtboxSelectExcelDir.Text = folderBrowserDialog1.FileName; }
// Then saving it as a .txt is what i do... :)
// Get the info seperated by tabs
String info = String.Empty;
using (StreamWriter sw = File.CreateText(folderBrowserDialog1.FileName)
{
sw.Write(//whatever info here);Make sure the info is seperated by tabs, to indicate different cells for example,
col1, row1\tcol2, row1\r\ncol1, row2\tcol2, row2
-
Hi Guys. I have just spent about 5 hours searching the web trying to find a solution to my problem. I am busy with a project where I am writing data to an Excel file. This works fine. I then want to save the Excel file to a pre-selected directory which the user select using the folderBrowserDialog. Now, I need to know how do I then save my file to the directry selected. I am displaying the Selected path in a txtbox. I only want to save the file to this directory. follderBrowserDialog code:
private void btSelectDirToSave\_Click(object sender, EventArgs e) { if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { txtboxSelectExcelDir.Text = folderBrowserDialog1.SelectedPath; } }
File save code:
string namefile; namefile = txtboxSelectExcelDir.Text; objExcel.ActiveWorkbook.SaveAs(namefile + "\_Nom022.xls",Excel.XlFileFormat.xlWorkbookNormal,Type.Missing,Type.Missing,Type.Missing, Type.Missing,Excel.XlSaveAsAccessMode.xlNoChange,Type.Missing,Type.Missing,Type.Missing,Type.Missing);
Any Help would be greatly appreciated as the file is currently not being saved to the selected directory but the Directory name is appended to the filename and saved somewhere else. :( :sigh: :(
Excellence is doing ordinary things extraordinarily well.
-
objExcel.ActiveWorkbook.SaveAs(Path.Combine(txtboxSelectExcelDir.Text, namefile + "_Nom022.xls"),...