S
Sahana M
Guest
Im using Windows Application in WPF C# Lang. and Console window is only for Print Statements. Writting a Program a Load XML value to Listbox and SAVE Listbox items to XML flie. Listbox take items from TextBox. when Add button click textbox item added to Listbox.
now my problem is : when im click on SAVE Button im getting some exception and application will close Automatically. Getting Exception Like This :
at System.IO.Filestream.Init(String Path, FileMode mode, FileAccess Access, Int32 rights, boolean useRights, FileStream Share, int32 buffersize, fileoption option, SECURITY_ATTRIBUTES secattrs, string msgPath, boolean bFfromProxy, boolean uselongpath, boolean checkhost)
at System.IO.FileStream..cattr(StringPath, FileMode, fileacces access, FileShare share, Int32 bufferSize)
at System.XML.xmldownloadmanager.getstream(Uri uri,ICredentials credentials, IWebProxy Proxy, REquestCachePolicy Cachepoliy)at System.XML.xmlURLResolver.getentity(Uri absoluteuri, string role, type ofobjectToReturn)
at System.Xml.xmltextReaderImpl.FinishInItUriString()
at System.Xml.xmlREaderSettings.CreateReader(String input uri, XmlParserContext Inputcontext)
at System.Xml.Linq.xElement.Load(String uri.LoadOption LoadOption)at MainWindow.Button_Click(object sender, Routed EventArgs e)
at System.Windows.EventRoute.InvokehandlerImpl(Objext Source, RoutedEventArgs Args, Boolean reRaise)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject Sender, RoutedEventArgs Args)
at System.Windows.Control.Premitives.buttonbase.OnClick()at System.Windows.Control.Button.OnClick()
at System.Windows.Control.Primitives.ButtonBase. OnmouseLeftButtonUp(MouseButtonEventArgs E)
at System.Windows.RoutedEventArgs.InvokeHandlers(Deleget Handler, ObjectTarget)
at System.Windows.EventRoute.InvokeHandlerImpl(Object Source, RoutedEventArgs Args, Boolean ReRaised)
at System.Windows.UIElement.ReRaiseEventAs(DependencyObject Sender, RoutedEventArgs Args, RoutedEvent NewEvent)
at System.Windows.UIElement.OnMouseUPThunk(Object Sender, MouseButtonEventArgs e)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegete Handler, Object Target)
at System.Windows.RoutedEventHandlerInfo invokeHandler(Object target, RoutedEventArgs RoutedEventargs)
at System.Windows.EventRoute.InvokeHandlerImpl(Object Source, RoutedEventArgs Args, Boolean Reraised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject Sender, RoutedEventArgs Args)
at System.Windows.UIElement.RaiseTrustedEvent (RoutedEventArgs Args)
at System.Windows.Input.InputManager.ProcessStageingArea()
at System.Windows.Input.InputManager.ProcessInput (InoutEventArgs Input)
at System.Windows.Input.InputProviderSite.ReportInput (InputReport inputreport)
My Code is :
private void LoadXML_Click(object sender, RoutedEventArgs e)
{
XElement element = XElement.Load("WH_Num.xml");
foreach (XElement item in element.Elements("Number1"))
ListBox_PhoneNumber.Items.Add(item.Value);
foreach (XElement item in element.Elements("Number2"))
ListBox_PhoneNumber.Items.Add(item.Value);
foreach (XElement item in element.Elements("Number3"))
ListBox_PhoneNumber.Items.Add(item.Value);
foreach (XElement item in element.Elements("Number4"))
ListBox_PhoneNumber.Items.Add(item.Value);
foreach (XElement item in element.Elements("Number5"))
MessageBox.Show("Number Loaded to XML");
}
private void SAVEXML_Click(object sender, RoutedEventArgs e)
{
try
{
information info = new information();
if (ListBox_PhoneNumber.Items.Count > 0) info.Number1 = ListBox_PhoneNumber.Items[0].ToString();
if (ListBox_PhoneNumber.Items.Count > 1) info.Number2 = ListBox_PhoneNumber.Items[1].ToString();
if (ListBox_PhoneNumber.Items.Count > 2) info.Number3 = ListBox_PhoneNumber.Items[2].ToString();
if (ListBox_PhoneNumber.Items.Count > 3) info.Number4 = ListBox_PhoneNumber.Items[3].ToString();
if (ListBox_PhoneNumber.Items.Count > 4) info.Number5 = ListBox_PhoneNumber.Items[4].ToString();
SaveXML.savedata(info, "WH_Num.xml");
MessageBox.Show("Data Saved");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Where im missing?? Why this exception is coming?? Anyone help me
Continue reading...
now my problem is : when im click on SAVE Button im getting some exception and application will close Automatically. Getting Exception Like This :
at System.IO.Filestream.Init(String Path, FileMode mode, FileAccess Access, Int32 rights, boolean useRights, FileStream Share, int32 buffersize, fileoption option, SECURITY_ATTRIBUTES secattrs, string msgPath, boolean bFfromProxy, boolean uselongpath, boolean checkhost)
at System.IO.FileStream..cattr(StringPath, FileMode, fileacces access, FileShare share, Int32 bufferSize)
at System.XML.xmldownloadmanager.getstream(Uri uri,ICredentials credentials, IWebProxy Proxy, REquestCachePolicy Cachepoliy)at System.XML.xmlURLResolver.getentity(Uri absoluteuri, string role, type ofobjectToReturn)
at System.Xml.xmltextReaderImpl.FinishInItUriString()
at System.Xml.xmlREaderSettings.CreateReader(String input uri, XmlParserContext Inputcontext)
at System.Xml.Linq.xElement.Load(String uri.LoadOption LoadOption)at MainWindow.Button_Click(object sender, Routed EventArgs e)
at System.Windows.EventRoute.InvokehandlerImpl(Objext Source, RoutedEventArgs Args, Boolean reRaise)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject Sender, RoutedEventArgs Args)
at System.Windows.Control.Premitives.buttonbase.OnClick()at System.Windows.Control.Button.OnClick()
at System.Windows.Control.Primitives.ButtonBase. OnmouseLeftButtonUp(MouseButtonEventArgs E)
at System.Windows.RoutedEventArgs.InvokeHandlers(Deleget Handler, ObjectTarget)
at System.Windows.EventRoute.InvokeHandlerImpl(Object Source, RoutedEventArgs Args, Boolean ReRaised)
at System.Windows.UIElement.ReRaiseEventAs(DependencyObject Sender, RoutedEventArgs Args, RoutedEvent NewEvent)
at System.Windows.UIElement.OnMouseUPThunk(Object Sender, MouseButtonEventArgs e)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegete Handler, Object Target)
at System.Windows.RoutedEventHandlerInfo invokeHandler(Object target, RoutedEventArgs RoutedEventargs)
at System.Windows.EventRoute.InvokeHandlerImpl(Object Source, RoutedEventArgs Args, Boolean Reraised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject Sender, RoutedEventArgs Args)
at System.Windows.UIElement.RaiseTrustedEvent (RoutedEventArgs Args)
at System.Windows.Input.InputManager.ProcessStageingArea()
at System.Windows.Input.InputManager.ProcessInput (InoutEventArgs Input)
at System.Windows.Input.InputProviderSite.ReportInput (InputReport inputreport)
My Code is :
private void LoadXML_Click(object sender, RoutedEventArgs e)
{
XElement element = XElement.Load("WH_Num.xml");
foreach (XElement item in element.Elements("Number1"))
ListBox_PhoneNumber.Items.Add(item.Value);
foreach (XElement item in element.Elements("Number2"))
ListBox_PhoneNumber.Items.Add(item.Value);
foreach (XElement item in element.Elements("Number3"))
ListBox_PhoneNumber.Items.Add(item.Value);
foreach (XElement item in element.Elements("Number4"))
ListBox_PhoneNumber.Items.Add(item.Value);
foreach (XElement item in element.Elements("Number5"))
MessageBox.Show("Number Loaded to XML");
}
private void SAVEXML_Click(object sender, RoutedEventArgs e)
{
try
{
information info = new information();
if (ListBox_PhoneNumber.Items.Count > 0) info.Number1 = ListBox_PhoneNumber.Items[0].ToString();
if (ListBox_PhoneNumber.Items.Count > 1) info.Number2 = ListBox_PhoneNumber.Items[1].ToString();
if (ListBox_PhoneNumber.Items.Count > 2) info.Number3 = ListBox_PhoneNumber.Items[2].ToString();
if (ListBox_PhoneNumber.Items.Count > 3) info.Number4 = ListBox_PhoneNumber.Items[3].ToString();
if (ListBox_PhoneNumber.Items.Count > 4) info.Number5 = ListBox_PhoneNumber.Items[4].ToString();
SaveXML.savedata(info, "WH_Num.xml");
MessageBox.Show("Data Saved");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Where im missing?? Why this exception is coming?? Anyone help me
Continue reading...