Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4022108
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:26:03+00:00 2026-05-20T10:26:03+00:00

I had a datagrid view, and I had exported to an Excel sheet. The

  • 0

I had a datagrid view, and I had exported to an Excel sheet. The code worked well, but when the Save As dialog appeared and saved the file I could not find the file and no error appeared.

My code

private void button1_Click(object sender, EventArgs e)
{
    try
    {
        using (new ExcelUILanguageHelper())
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.Filter = "Execl files (*.xls)|*.xls";
            saveFileDialog.FilterIndex = 0;
            saveFileDialog.RestoreDirectory = true;
            saveFileDialog.CreatePrompt = true;
            saveFileDialog.Title = "Export Excel File To";

            Excel.ApplicationClass ExcelApp = new Excel.ApplicationClass();
            ExcelApp.Application.Workbooks.Add(Type.Missing);
            ExcelApp.Columns.ColumnWidth = 30;
            for (int i = 0; i < DGData.Rows.Count; i++)
            {
                DataGridViewRow row = DGData.Rows[i];
                for (int j = 0; j < row.Cells.Count; j++)
                {
                    ExcelApp.Cells[i + 1, j + 1] = row.Cells[j].ToString();
                }
            }

            ExcelApp.ActiveWorkbook.SaveCopyAs(saveFileDialog.ShowDialog());
            ExcelApp.ActiveWorkbook.Saved = true;
            ExcelApp.Quit();
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show("Cancelled Operation");
        this.Close();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:26:04+00:00Added an answer on May 20, 2026 at 10:26 am

    When you call

    saveFileDialog.ShowDialog()
    

    it returns a DialogResult and not the selected filename. The SaveCopyAs method expects a filename.

    Check a tutorial of SaveFileDialog here to see how to get the selected filename. It should be something like:

    private void Form1_DoubleClick(object sender, System.EventArgs e)
    {
    if( this.saveFileDialog1.ShowDialog() == DialogResult.OK )
    {
        MessageBox.Show("The Save button was clicked or the Enter key was pressed" +
                        "\nThe file would have been saved as " +
                        this.saveFileDialog1.FileName);
    }
    else
        MessageBox.Show("The Cancel button was clicked or Esc was pressed");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Had a good search here but can't see anything that gets my mind in
I had an idea, if I add a python .py file to my C#
I have a DataGrid containing a small table. Until now, I had a double
I have data that I'm taking from an Excel sheet with the ultimate goal
I am trying to read an XML file using LINQ. I have had no
In my grid I had following line of code which disabled user's manual resizing:
How do you remove the header row from a Spark DataGrid? MX DataGrid had
Had an interesting discussion with some colleagues about the best scheduling strategies for realtime
Had a coworker ask me this, and in my brain befuddled state I didn't
Had a page that was working fine. Only change I made was to add

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.