GenericPackager can't read XML file in ISO Message - c#

I am trying to call in ISO Message from Website (ASP.NET). I imported all DLL and code. But while reading XML from GenericPackager class, file can't read exception is coming.
The same code is working fine in C# Windows application.
Here is the code:
IsoXML_Path = HttpContext.Current.Server.MapPath("~") + "PostCardFields.xml";
GenericPackager packager = new GenericPackager();
packager.readFile(IsoXML_Path);
ISOMsg isoMsg = new ISOMsg();
isoMsg.setPackager(packager);
Error in Exception:
Error reading (PATH)\PostCardFields.xml
(org.xml.sax.SAXException: SAX2 driver class org.apache.crimson.parser.XMLReaderImpl not found
java.lang.ClassNotFoundException: org.apache.crimson.parser.XMLReaderImpl)
(PATH) is the path of my XML file in directory. File is exists on that path.

Related

Load CSV into Neo4j from local path without modifying config

I need to load a CSV file into a Neo4j database using its .NET driver. I can use the following code to load the file.
var dataFile = "data.csv";
var driver = GraphDatabase.Driver(uri, AuthTokens.Basic(user, password));
using var session = driver.AsyncSession(x => x.WithDefaultAccessMode(AccessMode.Write));
await session.WriteTransactionAsync(async tx =>
{
var result = await tx.RunAsync(
$"LOAD CSV WITH HEADERS FROM 'file:///{dataFile}' AS line " +
"CREATE(:Artist { name: line.Name, year: toInteger(line.Year)})");
});
This requires that the file is located under the C:/Users/user/.Neo4jDesktop/relate-data/dbmss/dbms-502b0f7e-04e2-4c24-9472-528775921429/import/ directory. If the data.csv file is located under a different directory, and I provide the fully quantifying path, I get the following error.
var dataFile = "C:/Users/user/Desktop/data.csv";
System.AggregateException: 'One or more errors occurred. (Couldn't load the external resource at: file:/C:/Users/user/.Neo4jDesktop/relate-data/dbmss/dbms-502b0f7e-04e2-4c24-9472-528775921429/import/Users/user/Desktop/data.csv)'
I can fix this by commenting-out dbms.directories.import=import in Neo4j config. However, in my usecase, modifying config is not an option and writing to the .Neo4jDesktop/relate-data/dbmss/dbms-***/import/ is not allowed.
Any thoughts on how I can load CSV from any directory without altering Neo4j configuration?
Changing the config file when importing a file outside "import" folder is a hard rule set by Neo4j. Please chase them about it thru
https://neo4j.com/contact-us/
Why importing file to import folder is not allowed?

Issues with saving xml document to xml file in the output directory. c# Xamarin

I'm making an application that loads and saves profile nodes to an external xml document in my output directory. It worked fine when I was opening it from my Assets folder but since that is read only (I think) I need to have it read and write from the output directory or another folder.
Like this:
XmlDocument users = new XmlDocument();
users.Load("users.xml");
However I get this error when this code runs:
"System.IO.FileNotFoundException: Could not find file "/users.xml"."
I've ticked the secondary storage permissions but i'm still a bit confused about just referencing a file in the output directory.
Would also appreciate the help for saving too as I assume the same error will occur:
users.DocumentElement.AppendChild(user);
users.Save("users.xml");
Thank you in advance.
In xamarin form you can try this code to load xml file from PCL project.
var assembly = typeof(TestClass).GetTypeInfo().Assembly;
Stream stream = assembly.GetManifestResourceStream(“PrjectName.FileName”);
using (var reader = new System.IO.StreamReader(stream))
{
var serializer = new XmlSerializer(typeof(List<BuildOptions>)); var listData = (List<T>)serializer.Deserialize(reader);
}

How to read data from a text file if the file location is not known in c#?

This question have been asked earlier in StackOverFlow and answers are also marked in that post. But sadly the solution provided in
Read a file from an unknown location? does not solve my problem.
I am building a website and need to read data from a text file. The actual location of the file in my pc is: C:\Developments\TestProject\PettyCashSolution\PettyCashWeb\DataFile.txt and I
have tried below solutions from above link with no luck.
string sString = string.Empty;
string sStr = "";
StreamReader oStreamReader;
try
{
Try1
sStr = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "DataFile.txt");
This returns below:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\pettycashweb\af7f0870\c5ac294a\DataFile.txt
Try2
sStr = Path.Combine(Application.StartupPath, "DataFile.txt");
This returns below:
Compile Error: The name "Application" does not exist in the current context
Try3
oStreamReader = new StreamReader(File.OpenRead(Directory.GetCurrentDirectory().ToString() + "\\DataFile.txt"));
This returns below:
Exception: Could not find file 'C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\DataFile.txt'
oStreamReader = new StreamReader(sStr);
sString = oStreamReader.ReadLine();
}
catch (Exception ex)
{
}
Please also advice what should I do so that after publishing the web in server (iis) the read data from text file will work properly. Thanks.
You can get application path by AppDomain.CurrentDomain.BaseDirectory
Your code must be like this
sStr = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DataFile.txt");
you can use
HttpContext.Current.Request.ApplicationPath
then append string according to it.

Error replacing xml file #C:\Windows\System32\WindowsPowerShell

I am writing a console application where I'm trying to replace a xml file (xx.config) with other xml file(xx.config) which is at different folder with different data to the path C:\Windows\System32\WindowsPowerShell.
I'm getting following error
Could not find a part of the path C:\Windows\System32\WindowsPowerShell\xx.config
But there is the file at this path. I tried to load this file to XMLDocument then also same error occurred. Can anyone tell me what I'm doing wrong.
XDocument xmldoc = XDocument.Load(#"C:\test\xx.config");\loads good
XDocument xmldoc = XDocument.Load(#"C:\Windows\System32\WindowsPowerShell\xx.config");\error occurs
File.Move(#"C:\test\xx.config", >#"C:\Windows\System32\WindowsPowerShell\xx.config");\error occurs

loading xml document error in c#

I'm trying to load a document with xml in c#
the name of xml file is variable, here is problem...
string filename="test01.xml";
XmlDocument root = new XmlDocument();
root.Load(filename);
the above code give me error: unable to connect to remote server or unable to load
but the following code works
XmlDocument root = new XmlDocument();
root.Load("test01.xml");
why is that?
You can try to specify the whole path (absolute path) to the file (not only the filename).
So instead of writing "test01.xml" you can try to write "C:\[... path to the file here]\test01.xml" and it should work as intended.
If you specify only the file name, the application will probably look for the file in the current directory (value in Environment.CurrentDirectory). I just tested this in a sample application.
It's worth mentioning that if you use FileName property from OpenFileDialog class as a case with 'using variable', it contains PATH to the file (despite its name ;)).
Does your XML contains DTD declaration with URL? Most probably parser tries to resolve it, and fails, because, say, automatic proxy does not accept its request.

Categories