CodeJunky
asked on
WINDOWS PHONE 8.1 DEVELOPMENT Open File failure
Hi all,
I'm trying t open an XML file in WP8.1 dev environment (VS2013).
I can open an xml file that has been added to my project. great for testing....
I am creating a simple xml, hard coding the file, first on the phone than trying to open it. I keep getting errors that it can't open the file. Don't know what i'm missing here.
I'm trying t open an XML file in WP8.1 dev environment (VS2013).
I can open an xml file that has been added to my project. great for testing....
I am creating a simple xml, hard coding the file, first on the phone than trying to open it. I keep getting errors that it can't open the file. Don't know what i'm missing here.
An exception of type 'System.Xml.XmlException' occurred in SYSTEM.XML.NI.DLL but was not handled in user code
Additional information: Cannot open 'file:///C:/Data/SharedData/PhoneTools/AppxLayouts/9366RuSoftInformationTech.RuSafeVS.Debug_AnyCPU.John/RuSafe/RuSafe 102.xml'. The Uri parameter must be a file system relative path.
MAKE SURE THE PATH IS CORRECT
I believe that the key is in this statement, "The Uri parameter must be a file system relative path.", since you have a full path.
How are you reading the file?
How are you reading the file?
ASKER
This is just odd...
What I'm doing is creating an XML File under a subdirectory, such as \sub.
The file(s) are created just fine and they are presented on my phone screen so that I can select them.
The path is the same location as the files.
Not the RSCatalog_Active$ variable is the actual file name.
the function to read in the XML is below. If I have an xml file hard coded, within my project, which I've used for testing it works.
the error occurs at the point in the function....
Dim xmlData As XDocument = XDocument.Load(XMLFileName $)
But again I know the function is ok because it can read the xml file within my project.
What I'm doing is creating an XML File under a subdirectory, such as \sub.
The file(s) are created just fine and they are presented on my phone screen so that I can select them.
The path is the same location as the files.
Not the RSCatalog_Active$ variable is the actual file name.
Dim local As StorageFolder = PARENT_PATH
Dim dataFolder = Await local.GetFolderAsync("Sub")
'Dim RC_Catalog As StorageFile = dataFolder.GetFileAsync(RSCatalog_Active$)
FullFilePath$ = dataFolder.Path & "\" & RSCatalog_Active$ 'RC_Catalog.Path
ReadXMLData_MAIN(FullFilePath$)
the function to read in the XML is below. If I have an xml file hard coded, within my project, which I've used for testing it works.
Friend Sub ReadXMLData_MAIN(ByVal XMLFileName$)
Dim xmlData As XDocument = XDocument.Load(XMLFileName$)
Table_Main = From query In xmlData.Descendants("MAINTBL") Select New DATA_MAIN() With _
{ _
.sITEM_NAME = DirectCast(query.Element("sITEM_NAME").Value, String), _
.SID = DirectCast(query.Element("SID").Value, String) _
}
End Sub
the error occurs at the point in the function....
Dim xmlData As XDocument = XDocument.Load(XMLFileName
But again I know the function is ok because it can read the xml file within my project.
I would think that files within your project would have the correct relative path name. Files outside would need a different approach.
Example #1:
Full path = C:\folder1\folder1.1\folde r1.1.1\log .txt
Root = C:\folder1\folder1.1
Relative = folder1.1.1\log.txt
Example #2
Files:
C:\folder1\folder1.1\folde r1.1.1\log .txt
C:\folder2\folder2.1\folde r2.1.1\log .txt
C:\folder3\folder3.1\folde r3.1.1\log .txt
Full path = C:\folder3\folder3.1\folde r3.1.1\log .txt
Root = C:\folder1\folder1.1
Relative = ..\..\folder3.1\folder3.1. 1\log.txt
Example #1:
Full path = C:\folder1\folder1.1\folde
Root = C:\folder1\folder1.1
Relative = folder1.1.1\log.txt
Example #2
Files:
C:\folder1\folder1.1\folde
C:\folder2\folder2.1\folde
C:\folder3\folder3.1\folde
Full path = C:\folder3\folder3.1\folde
Root = C:\folder1\folder1.1
Relative = ..\..\folder3.1\folder3.1.
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 figured this out on my own.