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.
Unfortunately, activation email could not send to your email. Please try again.

How to set the default path when saving a file

Thread ID:

Created:

Updated:

Platform:

Replies:

6854 Sep 2,2003 12:57 AM Sep 2,2003 11:25 AM Windows Forms 1
loading
Tags: EditControl
Stéphane BLANC
Asked On September 2, 2003 12:57 AM

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 11:25 AM

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.

CONFIRMATION

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.

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.

;