bteam
asked on
WPF C# Application, Access Project Folder
I have created a new C# WPF Application in Visual Studio 2008. Within that project I have created a "Resources" folder containing a single .xml file. How can I access the new folder to obtain the xml file?
private void LoadRecentSearchItems()
{
XmlDocument doc = new XmlDocument();
doc.LoadXml("\\Resources\\RecentSearchItems.xml");
}
ASKER
Sorry man. That doesn't get it either.
Do you get an XmlException error message when your code runs? If so, can you post the message.
ASKER
System.Windows.Markup.Xaml ParseExcep tion was unhandled
Message="Cannot create instance of 'MainWindow' defined in assembly 'JezProjects, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Exception has been thrown by the target of an invocation. Error in markup file 'MainWindow.xaml' Line 1 Position 9."
Source="PresentationFramew ork"
LineNumber=1
LinePosition=9
StackTrace:
at System.Windows.Markup.Xaml ParseExcep tion.Throw Exception( String message, Exception innerException, Int32 lineNumber, Int32 linePosition, Uri baseUri, XamlObjectIds currentXamlObjectIds, XamlObjectIds contextXamlObjectIds, Type objectType)
at System.Windows.Markup.Xaml ParseExcep tion.Throw Exception( ParserCont ext parserContext, Int32 lineNumber, Int32 linePosition, String message, Exception innerException)
at System.Windows.Markup.Baml RecordRead er.CreateI nstanceFro mType(Type type, Int16 typeId, Boolean throwOnFail)
at System.Windows.Markup.Baml RecordRead er.GetElem entAndFlag s(BamlElem entStartRe cord bamlElementStartRecord, Object& element, ReaderFlags& flags, Type& delayCreatedType, Int16& delayCreatedTypeId)
at System.Windows.Markup.Baml RecordRead er.BaseRea dElementSt artRecord( BamlElemen tStartReco rd bamlElementRecord)
at System.Windows.Markup.Baml RecordRead er.ReadEle mentStartR ecord(Baml ElementSta rtRecord bamlElementRecord)
at System.Windows.Markup.Baml RecordRead er.ReadRec ord(BamlRe cord bamlRecord)
at System.Windows.Markup.Baml RecordRead er.Read(Bo olean singleRecord)
at System.Windows.Markup.Tree BuilderBam lTranslato r.ParseFra gment()
at System.Windows.Markup.Tree Builder.Pa rse()
at System.Windows.Markup.Xaml Reader.Loa dBaml(Stre am stream, ParserContext parserContext, Object parent, Boolean closeStream)
at System.Windows.Application .LoadBamlS treamWithS yncInfo(St ream stream, ParserContext pc)
at System.Windows.Application .DoStartup ()
at System.Windows.Application .<.ctor>b_ _0(Object unused)
at System.Windows.Threading.E xceptionWr apper.Inte rnalRealCa ll(Delegat e callback, Object args, Boolean isSingleParameter)
at System.Windows.Threading.E xceptionWr apper.TryC atchWhen(O bject source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
at System.Windows.Threading.D ispatcherO peration.I nvokeImpl( )
at System.Threading.Execution Context.ru nTryCode(O bject userData)
at System.Runtime.CompilerSer vices.Runt imeHelpers .ExecuteCo deWithGuar anteedClea nup(TryCod e code, CleanupCode backoutCode, Object userData)
at System.Threading.Execution Context.Ru n(Executio nContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.D ispatcherO peration.I nvoke()
at System.Windows.Threading.D ispatcher. ProcessQue ue()
at System.Windows.Threading.D ispatcher. WndProcHoo k(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndPr oc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.Disp atcherCall backOperat ion(Object o)
at System.Windows.Threading.E xceptionWr apper.Inte rnalRealCa ll(Delegat e callback, Object args, Boolean isSingleParameter)
at System.Windows.Threading.E xceptionWr apper.TryC atchWhen(O bject source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
at System.Windows.Threading.D ispatcher. InvokeImpl (Dispatche rPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
at MS.Win32.HwndSubclass.Subc lassWndPro c(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMetho ds.Dispatc hMessage(M SG& msg)
at System.Windows.Threading.D ispatcher. TranslateA ndDispatch Message(MS G& msg)
at System.Windows.Threading.D ispatcher. PushFrameI mpl(Dispat cherFrame frame)
at System.Windows.Application .RunIntern al(Window window)
at JezProjects.App.Main() in C:\Users\bballew\Documents \Visual Studio 2008\Projects\JezProjects\ JezProject s\obj\Debu g\App.g.cs :line 0
at System.AppDomain._nExecute Assembly(A ssembly assembly, String[] args)
at Microsoft.VisualStudio.Hos tingProces s.HostProc .RunUsersA ssembly()
at System.Threading.Execution Context.Ru n(Executio nContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHel per.Thread Start()
InnerException: System.Reflection.TargetIn vocationEx ception
Message="Exception has been thrown by the target of an invocation."
Source="mscorlib"
StackTrace:
at System.RuntimeTypeHandle.C reateInsta nce(Runtim eType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateI nstanceSlo w(Boolean publicOnly, Boolean fillCache)
at System.RuntimeType.CreateI nstanceImp l(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
at System.Activator.CreateIns tance(Type type, Boolean nonPublic)
at System.Windows.Markup.Baml RecordRead er.CreateI nstanceFro mType(Type type, Int16 typeId, Boolean throwOnFail)
InnerException: System.Xml.XmlException
Message="Data at the root level is invalid. Line 1, position 1."
Source="System.Xml"
LineNumber=1
LinePosition=1
SourceUri=""
StackTrace:
at System.Xml.XmlTextReaderIm pl.Throw(E xception e)
at System.Xml.XmlTextReaderIm pl.ParseRo otLevelWhi tespace()
at System.Xml.XmlTextReaderIm pl.ParseDo cumentCont ent()
at System.Xml.XmlLoader.Load( XmlDocumen t doc, XmlReader reader, Boolean preserveWhitespace)
at System.Xml.XmlDocument.Loa d(XmlReade r reader)
at System.Xml.XmlDocument.Loa dXml(Strin g xml)
at JezProjects.MainWindow.Loa dRecentSea rchItems() in C:\Users\bballew\Documents \Visual Studio 2008\Projects\JezProjects\ JezProject s\MainWind ow.xaml.cs :line 33
at JezProjects.MainWindow..ct or() in C:\Users\bballew\Documents \Visual Studio 2008\Projects\JezProjects\ JezProject s\MainWind ow.xaml.cs :line 27
InnerException:
Message="Cannot create instance of 'MainWindow' defined in assembly 'JezProjects, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Exception has been thrown by the target of an invocation. Error in markup file 'MainWindow.xaml' Line 1 Position 9."
Source="PresentationFramew
LineNumber=1
LinePosition=9
StackTrace:
at System.Windows.Markup.Xaml
at System.Windows.Markup.Xaml
at System.Windows.Markup.Baml
at System.Windows.Markup.Baml
at System.Windows.Markup.Baml
at System.Windows.Markup.Baml
at System.Windows.Markup.Baml
at System.Windows.Markup.Baml
at System.Windows.Markup.Tree
at System.Windows.Markup.Tree
at System.Windows.Markup.Xaml
at System.Windows.Application
at System.Windows.Application
at System.Windows.Application
at System.Windows.Threading.E
at System.Windows.Threading.E
at System.Windows.Threading.D
at System.Threading.Execution
at System.Runtime.CompilerSer
at System.Threading.Execution
at System.Windows.Threading.D
at System.Windows.Threading.D
at System.Windows.Threading.D
at MS.Win32.HwndWrapper.WndPr
at MS.Win32.HwndSubclass.Disp
at System.Windows.Threading.E
at System.Windows.Threading.E
at System.Windows.Threading.D
at MS.Win32.HwndSubclass.Subc
at MS.Win32.UnsafeNativeMetho
at System.Windows.Threading.D
at System.Windows.Threading.D
at System.Windows.Application
at JezProjects.App.Main() in C:\Users\bballew\Documents
at System.AppDomain._nExecute
at Microsoft.VisualStudio.Hos
at System.Threading.Execution
at System.Threading.ThreadHel
InnerException: System.Reflection.TargetIn
Message="Exception has been thrown by the target of an invocation."
Source="mscorlib"
StackTrace:
at System.RuntimeTypeHandle.C
at System.RuntimeType.CreateI
at System.RuntimeType.CreateI
at System.Activator.CreateIns
at System.Windows.Markup.Baml
InnerException: System.Xml.XmlException
Message="Data at the root level is invalid. Line 1, position 1."
Source="System.Xml"
LineNumber=1
LinePosition=1
SourceUri=""
StackTrace:
at System.Xml.XmlTextReaderIm
at System.Xml.XmlTextReaderIm
at System.Xml.XmlTextReaderIm
at System.Xml.XmlLoader.Load(
at System.Xml.XmlDocument.Loa
at System.Xml.XmlDocument.Loa
at JezProjects.MainWindow.Loa
at JezProjects.MainWindow..ct
InnerException:
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I had doc.LoadXML! I totally missed that thank you!
doc.Load(@"..\..\Resources