I am developing small application in Windows 6.5.3. For that I need to read one XML file from C drive. When I tried to read the file, I am getting the below error. I checked the file access. Its fine.
"Value does not fall within the expected range."
STACK TRACE
at System.IO.__Error.WinIOError(Int32 errorCode, String str)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials)
at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn)
at System.Xml.XmlReader.Create(String inputUri, XmlReaderSettings settings, XmlParserContext inputContext)
at System.Xml.XmlReader.Create(String inputUri, XmlReaderSettings settings)
at System.Xml.Linq.XElement.Load(String uri, LoadOptions options)
at FREEMobile.frmMainMenu.frmMainMenu_Load(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form._SetVisibleNotify(Boolean fVis)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at System.Windows.Forms.Application.Run(Form fm)
at FREEMobile.frmMainMenu.Main()
CODE
Dim faciltyXML As XElement
Dim strFileName As String = "C:\Users\xs1969\Desktop\FREEMobile\FREEMobile\Facility.xml"
faciltyXML = XElement.Load(strFileName, LoadOptions.None)
EDIT 1:
Thanks CTACKE. I did the following change. Its working fine.
Dim faciltyXML As XElement
Dim strAppDir As String = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase)
Dim strFullPathToMyFile As String = Path.Combine(strAppDir, "Facility.xml")
faciltyXML = XElement.Load(strFullPathToMyFile)