Hello,
So I have a program which basically takes a lot of reading and everytime we take a reading we want to save the file. Now the problem is I am using the Savedialog and calling the ShowDialog function. But what I am really looking for is it should just save the file automatically and not show the SaveDialog Box?
the code for Saving is as follows:
private bool SaveMeasureDialog() {SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.InitialDirectory = this.defaultRootPath; saveFileDialog.Filter = "Measured files (*.vlg)|*.vlg|All files (*.*)|*.*"; saveFileDialog.FilterIndex = 1; saveFileDialog.DefaultExt = "vlg"; saveFileDialog.RestoreDirectory = true; saveFileDialog.OverwritePrompt = true; if (!string.IsNullOrEmpty(this.filePath)) { FileInfo fileInfo = new FileInfo(this.filePath); saveFileDialog.InitialDirectory = this.defaultRootPath; saveFileDialog.FileName = "Measure1"; } bool flag = saveFileDialog.ShowDialog() == DialogResult.OK; if (flag) { this.SaveMeasure(saveFileDialog.FileName); } return !flag; } public void SaveMeasure(string fp) { FileStream fileStream = File.Create(fp); FileStream fileStream1 = fileStream; if (fileStream != null) { if (this.filePath != fp) { this.msr.IdNumber = Guid.NewGuid(); } MeasureXml.SaveMeasure(fileStream1, this.measure, this.RootPathDb); this.filePath = fp; this.changed = false; this.OnFileInfoChanged(EventArgs.Empty); } }
This is the part of the code where it reads the file and save the measurement too in the file. Now what I am really looking for is to eliminate the SaveFileDialog.ShowDialog part and instead just save the file cos I no what path I want to save it (by default it will be the rootPath ) and also the name is pretty much always "Measure".
Thanks in advance for any suggestions or solutions!!
:-))