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 8518429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:58:31+00:00 2026-06-11T05:58:31+00:00

I have an application in which the user interacts with a database and prepares

  • 0

I have an application in which the user interacts with a database and prepares a report of what he needs. The item prices are listed in the database. Once he chooses the items then he generates a report in Excel format. When he hits the Generate a Report button, he is asked where to save the report. These are all good. The problem is that when he saves the report and hits the Generate A Report button, he is able to save the same file with the same name at the same location when a file of the same name exists at that location. It basically replaces the old one. I wrote a code to check for the file if it exists and it works but the problem is that it does not appear at the instant when you are saving the file. It appears before. What I want is when I try to save the file at any location, it gives me at that instant that “The file exists and do you want to replace it with it”, more like Windows dialog when you try to save a word document into a location where there is a document with the same name.

If anyone needs any clarifications please comment, I am online most of the times.

Here is the code

  private void btnRunReport_Click(object sender, EventArgs e)
    {
        if (cmbReportsList.SelectedIndex != -1)
        {
            _qry = new QueryMgt();
            OpenProjectDb();

            string _sProjectName = (dbManager.ExecuteScalar(CommandType.Text, _qry.GetProjectFileName())).ToString();
            CloseProjectDb();
            if (cmbReportsList.SelectedIndex == 0)
            {


                SaveFile.Filter = "excel 2007 (*.xlsx)|*.xlsx";                   
                SaveFile.DefaultExt = "xlsx";
                SaveFile.FileName = _sProjectName + " Report1";
                strFilepath = System.IO.Path.GetFullPath(SaveFile.FileName);



                    if (SaveFile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {

                        this.Text = System.IO.Path.GetFileName(SaveFile.FileName);
                        strFilepath = System.IO.Path.GetFullPath(SaveFile.FileName);
                        if (strFilepath.Length > 218) { strFilepath = StringMgt.Left(strFilepath, 218); }

                        btnRunReport.Visible = false;
                        bg1804Rpt.RunWorkerAsync();
                        Application.DoEvents();
                    }




            }
            else if (cmbReportsList.SelectedIndex == 1)
            {
                SaveFile.FileName = _sProjectName + " Report2";
                SaveFile.Filter = "excel 2007 (*.xlsx)|*.xlsx"; 
                SaveFile.DefaultExt = "xlsx";

                if (SaveFile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    //SaveFile.FileName = "Report2";
                    this.Text = System.IO.Path.GetFileName(SaveFile.FileName);
                    strFilepath = System.IO.Path.GetFullPath(SaveFile.FileName);
                    if (strFilepath.Length > 218) { strFilepath = StringMgt.Left(strFilepath, 218); }

                    btnRunReport.Visible = false;
                    bgMCRpt.RunWorkerAsync();
                    Application.DoEvents();
                }
            }
            else if (cmbReportsList.SelectedIndex == 2)
            {
                _qry = new QueryMgt();
                _formula = new FormulaMgt();
                string sSQL;
                string chrCountryName = "";

                OpenProjectDb();
                OpenTableDb();

                DataSet dsProjectSpec;
                DataSet dsCountry;

                sSQL = _qry.GetProjectSpec().ToString();
                dsProjectSpec = dbManager.ExecuteDataSet(CommandType.Text, sSQL);

                sSQL = _qry.GetCountry().ToString();
                dsCountry = dbManagerTable.ExecuteDataSet(CommandType.Text, sSQL);

                foreach (DataRow row in dsCountry.Tables[0].Select("pk_lngCountryID ='" + dsProjectSpec.Tables[0].Rows[0]["lngCountryId"] + "'"))
                {
                    chrCountryName = row["chrCountryName"].ToString();
                    break;
                }
                SaveFile.FileName = _sProjectName + " Report3";

                SaveFile.Filter = "excel 2007 (*.xlsx)|*.xlsx"; 
                SaveFile.DefaultExt = "xlsx";
                // SaveFile.Filter = "Microsoft Office Excel Worksheet (*.xlsx)|*.xls|All files (*.*)|*.*";
                if (SaveFile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    //SaveFile.FileName = "Report3";
                    this.Text = System.IO.Path.GetFileName(SaveFile.FileName);
                    strFilepath = System.IO.Path.GetFullPath(SaveFile.FileName);
                    if (strFilepath.Length > 218) { strFilepath = StringMgt.Left(strFilepath, 218); }

                    btnRunReport.Visible = false;
                    bgMDRpt.RunWorkerAsync();
                    Application.DoEvents();
                }
            }
        }
        else if (cmbReportsList.SelectedIndex == -1)
        {
            MessageBox.Show("Please select any report", "Info", MessageBoxButtons.OK,    MessageBoxIcon.Exclamation);
        }
    }
  • 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-06-11T05:58:32+00:00Added an answer on June 11, 2026 at 5:58 am

    You have not provided any code so I am left wondering.

    But are you using SaveFileDialog? If not, I highly suggest it. It provides that functionality.

    SaveFileDialog sfd = new SaveFileDialog();
    sfd.OverwritePrompt = true;
    if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
    {
        // Do Something
        // Access the filename they choose via: ofd.FileName
    }
    

    And if the user selects a file that exists, they will be asked if they are sure they want to overwrite it.

    SaveFileDialog also has several properties you can define. Such as the Filter property for defining acceptable file extensions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a C# console application, which interacts with a SQL Server Database, and
I have a .Net application which interacts with a DB2 database (Entity Framework, not
I have a windows form application which interacts with a remote database. the database
I have the application in which user select the particular folder and all the
I have developed a application in which user select the particular folder and it
I have developed a application in which user select the particular folder and it
I have a web application in which a user has to upload images to
I have a simple web application which lets the user upload local user data
i have created an application which show data from user current location. I want
I have an application in which I want to authenticate a user from a

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.