Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Saving Diagram to local file system and loading it (Read 2654 times)
padmavathi
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 23
Joined: Jun 29th, 2010
Saving Diagram to local file system and loading it
Jun 29th, 2010 at 8:44am
Print Post  
Hi
I am very new to DiagramLite component. Currently evaluating this.
My requirement is I should be able to Save the diagram constructed into local file system and again load it from that location into another application.
How can I do that in DiagramLite, since the source code given has used Isolated Stream File Storage.
But I would like to achieve this using SaveFileDialog box and OpenDialogue box.
So, can anyone tell me how can I write the diagram content to an xml file to be saved onto local file system?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Saving Diagram to local file system and loadin
Reply #1 - Jun 29th, 2010 at 9:11am
Print Post  
Hi,

Try using the SaveToXml and LoadFromXml overloaded methods that take a Stream argument. When saving, you can get the required stream by calling the OpenFile method of SaveFileDialog.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
padmavathi
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 23
Joined: Jun 29th, 2010
Re: Saving Diagram to local file system and loadin
Reply #2 - Jun 29th, 2010 at 11:39am
Print Post  
Yes I tried this Stoyan as follows:
string strDiagramContent=diagram.SaveToString(SaveToStringFormat.Xml);
SaveFileDialog saveFileDlg = new SaveFileDialog();
saveFileDlg.Filter = "XML Files (.xml)|*.xml|All Files|*.*";
bool? isSaveDialogShown = saveFileDlg.ShowDialog();
if (isSaveDialogShown == true)
{
using (StreamWriter stream = new StreamWriter(saveFileDlg.OpenFile()))
{
stream.Write(strDiagramContent);
stream.Close();
}

}


But the problem is with the stream.Write method. Here we need to pass the string form of the entire diagram.
When I did this, an xml file is saved without any error. But When I tried to Load this xml file using stream as follows I got an exception:There is no Unicode byte order mark. Cannot switch to Unicode.

//here is the code i have written to load the xml file
OpenFileDialog openFileDlg = new OpenFileDialog();
bool? isOpenFileDlgShown = openFileDlg.ShowDialog();
if (isOpenFileDlgShown == true)
{
FileInfo file = openFileDlg.File;
Stream str = file.OpenRead();
diagram.LoadFromXml(str);
}


Plz correct where I have done the mistake?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Saving Diagram to local file system and loadin
Reply #3 - Jun 29th, 2010 at 1:15pm
Print Post  
Try this:

Code
Select All
private void OnSave(object sender, RoutedEventArgs e)
{
	var saveFileDlg = new SaveFileDialog
	{
		Filter = "XML Files (.xml)|*.xml|All Files|*.*"
	};
	if (saveFileDlg.ShowDialog() == true)
	{
		using (var stream = saveFileDlg.OpenFile())
			diagram.SaveToXml(stream);
	}
}

private void OnLoad(object sender, RoutedEventArgs e)
{
	var openFileDlg = new OpenFileDialog();
	if (openFileDlg.ShowDialog() == true)
	{
		var file = openFileDlg.File;
		using (var stream = file.OpenRead())
			diagram.LoadFromXml(stream);
	}
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
padmavathi
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 23
Joined: Jun 29th, 2010
Re: Saving Diagram to local file system and loadin
Reply #4 - Jun 30th, 2010 at 7:16am
Print Post  
Thanks a ton. Yes..its helping and now I am able to do Save and Load without any problem.


Thanks & Regards
Padma
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint