Click here to Skip to main content
15,886,873 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: Not able to read the Detail property of Exception, when it is shown in the Quick Watch Pin
simpledeveloper11-Feb-19 6:59
simpledeveloper11-Feb-19 6:59 
QuestionBindingSource Implementation in .net Win Forms Pin
rjto2-Jan-19 5:01
rjto2-Jan-19 5:01 
AnswerRe: BindingSource Implementation in .net Win Forms Pin
Pete O'Hanlon2-Jan-19 5:27
mvePete O'Hanlon2-Jan-19 5:27 
GeneralRe: BindingSource Implementation in .net Win Forms Pin
rjto2-Jan-19 5:36
rjto2-Jan-19 5:36 
GeneralRe: BindingSource Implementation in .net Win Forms Pin
mtoha16-Jan-19 16:19
professionalmtoha16-Jan-19 16:19 
GeneralRe: BindingSource Implementation in .net Win Forms Pin
Pete O'Hanlon16-Jan-19 20:59
mvePete O'Hanlon16-Jan-19 20:59 
GeneralRe: BindingSource Implementation in .net Win Forms Pin
mtoha16-Jan-19 21:02
professionalmtoha16-Jan-19 21:02 
QuestionDuplicate confirm save prompt when using SaveFileDialog Pin
manic_drummer1-Jan-19 12:39
manic_drummer1-Jan-19 12:39 
I'm writing a C# WinForms .NET app in VS 2017 (v15.9.4) that is having a peculiar problem when saving a file. The file already exists and I am dutifully prompted by the SaveFileDialog to confirm overwrite with the following...

"[filename.ext] already exists. Do you want to replace it? [Yes][No]"

Problem: After clicking Yes in the above prompt, I get another prompt...

"[fullpath.ext] already exists. Do you want to replace it? [Yes][No]"

I can't find the cause of the second prompt. Here's my code to programmatically create the SaveFileDialog...

C#
private void mnuSaveAs_Click(object sender, EventArgs e)
        {
            if (OurQuestion.intQuestionType <= 0)
            {
                MessageBox.Show("No question exists. Please create a question and click Done button before saving.",
                                "oops.", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Title = "Save As...";
                sfd.Filter = "Trivia Question (*.tq)|*.tq";
                DialogResult sfdresult = sfd.ShowDialog();
                if (sfdresult == DialogResult.OK)
                {
                    sslblCurrentOp.Text = "Saving...";
                    strFilePath = sfd.FileName;
                    mnuSave.PerformClick();
                    blFileNeedsSaving = false;
                    sslblCurrentOp.Text = "Ready.";
                    ssMain.Refresh();
                    this.Text = "TriviaPad v3.0 - " + Path.GetFileNameWithoutExtension(strFilePath);
                    mnuSave.Enabled = tsbtnSave.Enabled = true;
                }
            }
        }

And here's the code for sf.SaveFile(), which is located in a .dll...

C#
public void SaveFile(string strfilepath, clsQuestion SentQuestion)
        {
            Stream savestream = null;
            try
            {
                savestream = new FileStream(strfilepath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                using (BinaryWriter bw = new BinaryWriter(savestream))
                {
                    savestream = null;

                    bw.Write("3.0");
                    bw.Write(SentQuestion.intQuestionType);

                    if (SentQuestion.intQuestionType < 4)
                    {
                        bw.Write(SentQuestion.strQuestion);
                        bw.Write(SentQuestion.intPoints);

                        bw.Write(SentQuestion.blQuestionImagePresent);
                        if (SentQuestion.blQuestionImagePresent == true)
                        {
                            bw.Write(SentQuestion.bytQuestionImage.Length);
                            bw.Write(SentQuestion.bytQuestionImage);
                        }
                        bw.Write(SentQuestion.blQuestionAudioPresent);
                        if (SentQuestion.blQuestionAudioPresent == true)
                        {
                            bw.Write(SentQuestion.bytQuestionAudio.Length);
                            bw.Write(SentQuestion.bytQuestionAudio);
                        }

                        bw.Write(SentQuestion.blIncludeTimer);
                        if (SentQuestion.blIncludeTimer == true)
                            bw.Write(SentQuestion.intTimerTime);

                        if (SentQuestion.intQuestionType == 1)
                        {
                            // Multiple Choice variables...
                            bw.Write(SentQuestion.blAIsChecked);
                            bw.Write(SentQuestion.strAnswerA);
                            bw.Write(SentQuestion.blAIsCorrect);
                            bw.Write(SentQuestion.blBIsChecked);
                            bw.Write(SentQuestion.strAnswerB);
                            bw.Write(SentQuestion.blBIsCorrect);
                            bw.Write(SentQuestion.blCIsChecked);
                            if (SentQuestion.blCIsChecked == true)
                            {
                                bw.Write(SentQuestion.strAnswerC);
                                bw.Write(SentQuestion.blCIsCorrect);
                            }
                            bw.Write(SentQuestion.blDIsChecked);
                            if (SentQuestion.blDIsChecked == true)
                            {
                                bw.Write(SentQuestion.strAnswerD);
                                bw.Write(SentQuestion.blDIsCorrect);
                            }
                        }
                        else if (SentQuestion.intQuestionType == 2)
                        {
                            // True Or False variables...
                            bw.Write(SentQuestion.blTrueOrFalseAnswer);
                        }
                        else if (SentQuestion.intQuestionType == 3)
                        {
                            // Fill-In-The-Blank variables...
                            bw.Write(SentQuestion.strFIBAnswer);
                        }

                        // Answer Response stuff...
                        bw.Write(SentQuestion.strCAR);
                        bw.Write(SentQuestion.strIAR);

                        bw.Write(SentQuestion.blCARImagePresent);
                        if (SentQuestion.blCARImagePresent == true)
                        {
                            bw.Write(SentQuestion.bytCARImage.Length);
                            bw.Write(SentQuestion.bytCARImage);
                        }
                        bw.Write(SentQuestion.blCARAudioPresent);
                        if (SentQuestion.blCARAudioPresent == true)
                        {
                            bw.Write(SentQuestion.bytCARAudio.Length);
                            bw.Write(SentQuestion.bytCARAudio);
                        }

                        bw.Write(SentQuestion.blIARImagePresent);
                        if (SentQuestion.blIARImagePresent == true)
                        {
                            bw.Write(SentQuestion.bytIARImage.Length);
                            bw.Write(SentQuestion.bytIARImage);
                        }

                        bw.Write(SentQuestion.blIARAudioPresent);
                        if (SentQuestion.blIARAudioPresent == true)
                        {
                            bw.Write(SentQuestion.bytIARAudio.Length);
                            bw.Write(SentQuestion.bytIARAudio);
                        }
                    }
                    else if (SentQuestion.intQuestionType == 4)
                    {
                        bw.Write(SentQuestion.MatchUp.strMatchUpTitle);
                        bw.Write(SentQuestion.MatchUp.strTopicName);
                        bw.Write(SentQuestion.MatchUp.intPoints);
                        bw.Write(SentQuestion.MatchUp.blPenaltyPoints);

                        bw.Write(SentQuestion.MatchUp.blMatchUpTitleImagePresent);
                        if (SentQuestion.MatchUp.blMatchUpTitleImagePresent)
                        {
                            bw.Write(SentQuestion.MatchUp.bytMatchUpTitleImage.Length);
                            bw.Write(SentQuestion.MatchUp.bytMatchUpTitleImage);
                        }

                        bw.Write(SentQuestion.MatchUp.blStartAudioPresent);
                        if (SentQuestion.MatchUp.blStartAudioPresent)
                        {
                            bw.Write(SentQuestion.MatchUp.bytStartAudio.Length);
                            bw.Write(SentQuestion.MatchUp.bytStartAudio);
                        }

                        bw.Write(SentQuestion.MatchUp.blSoundtrackAudioPresent);
                        if (SentQuestion.MatchUp.blSoundtrackAudioPresent)
                        {
                            bw.Write(SentQuestion.MatchUp.bytSoundtrackAudio.Length);
                            bw.Write(SentQuestion.MatchUp.bytSoundtrackAudio);
                        }

                        bw.Write(SentQuestion.MatchUp.blEndAudioPresent);
                        if (SentQuestion.MatchUp.blEndAudioPresent)
                        {
                            bw.Write(SentQuestion.MatchUp.bytEndAudio.Length);
                            bw.Write(SentQuestion.MatchUp.bytEndAudio);
                        }

                        // Now let's get the match items!
                        bw.Write(SentQuestion.MatchUp.intTotalMatchItems);
                        bw.Write(SentQuestion.MatchUp.strMatchType);

                        // If there are any match items, write 'em!
                        if (SentQuestion.MatchUp.strMatchType == "T")
                        {
                            if (SentQuestion.MatchUp.lstMatchItems.Count > 0)
                            {
                                for (int iii = 0; iii < SentQuestion.MatchUp.lstMatchItems.Count; iii++)
                                {
                                    bw.Write(SentQuestion.MatchUp.lstMatchItems[iii].strMatchText);
                                    bw.Write(SentQuestion.MatchUp.lstMatchItems[iii].blMatchIsCorrect);
                                }
                            }
                        }
                        else if (SentQuestion.MatchUp.strMatchType == "I")
                        {
                            for (int iii = 0; iii < SentQuestion.MatchUp.lstMatchItems.Count; iii++)
                            {
                                bw.Write(SentQuestion.MatchUp.lstMatchItems[iii].bytMatchImage.Length);
                                bw.Write(SentQuestion.MatchUp.lstMatchItems[iii].bytMatchImage);
                                bw.Write(SentQuestion.MatchUp.lstMatchItems[iii].blMatchIsCorrect);
                            }
                        }
                    }
                }
            }
            finally
            {
                if (savestream != null)
                    savestream.Dispose();
            }
        }


My guess is that this line of code...

C#
savestream = new FileStream(strfilepath, FileMode.OpenOrCreate, FileAccess.ReadWrite);


...is where the problem is caused. According to MSDN documentation, a FileStream declaration also has 14 overloads besides the three necessary parameters listed above, but no further info is available on what those overloads are. If this line of code requires an overload to prevent that second confirm prompt, what is it? I can't find any info anywhere about it.
AnswerRe: Duplicate confirm save prompt when using SaveFileDialog Pin
Dave Kreskowiak1-Jan-19 14:22
mveDave Kreskowiak1-Jan-19 14:22 
QuestionVB.net Chained Combo Boxes in Entity framework Pin
Member 1205292129-Dec-18 0:53
Member 1205292129-Dec-18 0:53 
AnswerRe: VB.net Chained Combo Boxes in Entity framework Pin
Gerry Schmitz30-Dec-18 8:58
mveGerry Schmitz30-Dec-18 8:58 
QuestionWrong calculator result in VB.net Pin
Member 1410203528-Dec-18 7:18
Member 1410203528-Dec-18 7:18 
AnswerRe: Wrong calculator result in VB.net Pin
Dave Kreskowiak28-Dec-18 7:31
mveDave Kreskowiak28-Dec-18 7:31 
AnswerRe: Wrong calculator result in VB.net Pin
Richard MacCutchan28-Dec-18 21:52
mveRichard MacCutchan28-Dec-18 21:52 
QuestionRole Based Security Pin
latakurekar25-Dec-18 23:23
latakurekar25-Dec-18 23:23 
AnswerRe: Role Based Security Pin
Eddy Vluggen25-Dec-18 23:43
professionalEddy Vluggen25-Dec-18 23:43 
AnswerRe: Role Based Security Pin
Nathan Minier26-Dec-18 2:37
professionalNathan Minier26-Dec-18 2:37 
QuestionDoes Dotnet Core Framework required for deploying dotnet core application on Windows IIS? Pin
Syed Shakeer Hussain20-Dec-18 16:42
Syed Shakeer Hussain20-Dec-18 16:42 
AnswerRe: Does Dotnet Core Framework required for deploying dotnet core application on Windows IIS? Pin
Eddy Vluggen22-Dec-18 20:55
professionalEddy Vluggen22-Dec-18 20:55 
QuestionCustom Windows Forms WebBrowser issues .Net Pin
Member 1184067019-Dec-18 11:28
Member 1184067019-Dec-18 11:28 
AnswerRe: Custom Windows Forms WebBrowser issues .Net Pin
Dave Kreskowiak19-Dec-18 13:23
mveDave Kreskowiak19-Dec-18 13:23 
GeneralRe: Custom Windows Forms WebBrowser issues .Net Pin
Member 1184067019-Dec-18 18:28
Member 1184067019-Dec-18 18:28 
GeneralRe: Custom Windows Forms WebBrowser issues .Net Pin
Pete O'Hanlon19-Dec-18 21:16
mvePete O'Hanlon19-Dec-18 21:16 
AnswerRe: Custom Windows Forms WebBrowser issues .Net Pin
Richard Deeming20-Dec-18 1:51
mveRichard Deeming20-Dec-18 1:51 
Questiondifference between angular 1 2 3 4 5 6 and 7 Pin
Mukesh2113-Dec-18 22:48
Mukesh2113-Dec-18 22:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.