Question

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)
Was it helpful?

Solution

There is no "C" drive in Windows Mobile. There are no drive letters at all. It looks like you're trying to open a file on your PC, but the Windows Mobile device is, for all intents and purposes, a completely separate device. Even if it's the emulator, it's a virtual machine and has no notion of the hosting PC's file system.

You must get the file into the device's file system. You could add it as a Content item to your project, which would get Studio to push it to the device when it deploys the app. You could share the PC folder through the emulator settings, which would mount the folder on the device file system as "\Storage Card" IIRC. You could copy the file over with a tool like Remote File Viewer. There are loads of ways to get the file to the device, but trying to open it directly from the PC will not work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top