Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you don't need to change the filename, but only the folder where this file is saved, then you can use the <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.folderbrowserdialog.aspx" rel="nofollow">FolderBrowserDialog</a> to ask just the folder where the file will be saved</p> <pre><code>private void button2_Click(object sender, System.EventArgs e) { FolderBrowserDialog fbd = new FolderBrowserDialog(); fbd.Description = "Select the destination folder"; fbd.ShowNewFolderButton = true; fbd.RootFolder = Environment.SpecialFolder.Personal; if( fbd.ShowDialog() == DialogResult.OK ) { string folderName = fbd.SelectedPath; .... the rest of your excel export code ..... // Pass the full path to the SaveAs method string fullPathName = Path.Combine(folderName, "csharp.net-informations.xls"); xlWorkBook.SaveAs(fullPathName, .....); ..... MessageBox.Show("Excel file created , you can find the file in: " + fullPathName); } </code></pre> <p>If you need to change also the file name, then you need to use a SaveFileDialog instance. </p> <pre><code> SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "Excel files (*.xls)|*.xls|All files (*.*)|*.*" ; sfd.FilterIndex = 1 ; sfd.RestoreDirectory = true ; sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal); if(sfd.ShowDialog() == DialogResult.OK) { if(sfd.FileName.Length &gt; 0) { ... the rest of your excel code here .... // sfd.FileName already contains the full path so xlWorkBook.SaveAs(sfd.FileName, .....); } } else { if(MessageBox.Show("Are you sure you want to quit without saving?", "Quitting", MessageBoxButtons.YesNo) == DialogResult.No) { // This important to stop the Form to close if this button is the Cancel/AcceptButton // or its property DialogResult is not DialogResult.None this.DialogResult = DialogResult.None; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload