AD
Administrator
Syncfusion Team
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.