We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to set the default path when saving a file

Thread ID:





6854 Sep 2,2003 04:57 AM UTC Sep 2,2003 03:25 PM UTC WinForms 1
Tags: EditControl
Stéphane BLANC
Asked On September 2, 2003 04:57 AM UTC

Hi, I would like to know how to set the default path when we call the .save() or .saveAs() methods ? (it would be very usefull to set this path to the project path for example...) Thanks for your help Stéphane

Administrator [Syncfusion]
Replied On September 2, 2003 03:25 PM UTC

Hi Stephane, Thanks for your suggestion. We have identified this as a feature request (QA# 250) and will try our best to accomodate this in our future releases. It would be possible to get around using the built-in logic for saving pretty easily. All the EditControl does is call SaveFile() from the EditData member, which in turn iterates through the lines and saves out the stream.You could simply perform this in your own save method, and perform default path logic, etc. Below would be the default implementation which could be modified to suite your needs : private void Save() { if (editControl1.CurrentFile == "Untitled.txt") { SaveAs(); } else { SaveFile(editControl1.CurrentFile); } } private void SaveAs() { if (!editControl1.HasContent) { //show custom error message return; } SaveFileDialog dlg = new SaveFileDialog(); //specify whichever filters are desired dlg.Filter = "CSharp files (*.cs)|*.cs"; dlg.FilterIndex = 1; if (dlg.ShowDialog() == DialogResult.OK) { editControl1.CurrentFile = dlg.FileName; SaveFile(editControl1.CurrentFile); } } private bool SaveFile(string fileName) { if ((fileName != null) && (fileName != string.Empty)) { try { System.IO.FileInfo fileInfo = new System.IO.FileInfo(fileName); if (fileInfo.Exists) { if ((fileInfo.Attributes & System.IO.FileAttributes.ReadOnly) == System.IO.FileAttributes.ReadOnly) { //read only - custom error message return false; } } System.IO.StreamWriter strWriter = new System.IO.StreamWriter(fileName, false, editControl1.TextEncoding); int lnLast = editControl1.Lines.Length; for (int i = 1; i < lnLast; i++) { strWriter.Write(editControl1.Lines[i-1] + "\r\n"); } if (editControl1.Lines[lnLast-1].Length > 0) { strWriter.Write(editControl1.Lines[lnLast-1]); } strWriter.Close(); return true; } catch (System.IO.IOException e) { //display custom error message return false; } } else { //custom error message return false; } } Hope this helps. Regards, Guru Patwal.


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon