I have a test case which validates an XML file.
When using VS2010 with .Net 3.5 framework, the below code works perfectly fine, i am able to load the XML file. My file is location is Source folder of the application.
XmlDocument doc = new XmlDocument();
try
{
doc.Load("Terms_and_Conditions.xml");
XmlNode node;
XmlElement root = doc.DocumentElement;
//Select and display the value of the element.
node = root.SelectSingleNode(NodeSelection);
return node.InnerText;
}
catch (Exception ex)
{
throw ex;
}
Solution Folder:
When I run the same code in .Net 4.6.1, file path resolves to
C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\Terms_and_Conditions.xml
Anyone have an idea why this issue with .Net 4.6.1
This happens because your unit tests run in the test runner, which is located in the Common7 folder and not in your projects bin folder. Since you specify a relative path to the xml file, the program will look for the file in the current folder, which is the Common7 folder.
Thanks everyone for the quick help.
Here is how I solved the problem with above link.
XmlDocument doc = new XmlDocument();
try
{
var path = System.IO.Directory.GetParent(System.IO.Directory.GetParent(TestContext.CurrentContext.TestDirectory).ToString());
doc.Load("Terms_and_Conditions.xml");
XmlNode node;
XmlElement root = doc.DocumentElement;
//Select and display the value of the element.
node = root.SelectSingleNode(NodeSelection);
return node.InnerText;
}
catch (Exception ex)
{
throw ex;
}
Related
When executing following code in docker context, the page just hangs and I do not get any exceptions either:
File file = fileService.createTempFile('some-file.xlsx')
log.info("CREATED EXCEL FILE : ${file.path}")
Workbook workbook = new SXSSFWorkbook(SXSSFWorkbook.DEFAULT_WINDOW_SIZE)
log.info("WORKBOOK CREATED")
workbook.createSheet(WorkbookUtil.createSafeSheetName('TEST'))
log.info("SHEET CREATED")
FileOutputStream fos = new FileOutputStream(file)
workbook.write(fos)
//workbook.dispose()
fos.close()
I can see the file is craeted and also see WORKBOOK CREATED log generated but nothing after that.
This happens only when running the code in the docker container and not when I run the app outside of docker context.
I am using poi 4.1.2 and jdk 11.0.16.
UPDATE:
I have read on other posts about the temp directory not existing or not being writable. Just to test this out, I went to the node and created pre-defined folder with all read write permissions as well and updated the code to point SXXF to write to that temp folder as well :
try {
//THIS FOLDER ALREADY EXISTS IN NODE AND HAS ALL PERMS
String path = '/usr/local/tomcat/temp/reporting-service-16769203353988068118/'
File tmpdir = new File(path)
log.info("TMP DIR IS ${tmpdir.path}")
File file = new File("${tmpdir.path}/surveyQuestionExport.xlsx")
log.info("CREATED EXCEL FILE : ${file.path}")
TempFile.setTempFileCreationStrategy(new DefaultTempFileCreationStrategy(tmpdir))
Workbook workbook = new SXSSFWorkbook(new XSSFWorkbook(), SXSSFWorkbook.DEFAULT_WINDOW_SIZE)
log.info("WORKBOOK CREATED")
workbook.createSheet(WorkbookUtil.createSafeSheetName('TEST'))
log.info("SHEET CREATED")
FileOutputStream fos = new FileOutputStream(file)
workbook.write(fos)
workbook.dispose()
fos.flush()
fos.close()
return file
} catch (Exception ex) {
log.error("EXPORT FAILED", ex)
}
But still same issue.
I know this question was asked hundred times but for some reason accepted answers don't work for me.
I can write to device internal memory with this code:
File root = context.getExternalFilesDir(null);
root = new File(root, DATA_FOLDER);
if (!root.exists())
root.mkdir();
File pack = new File(root, "pack???");
if (!pack.exists())
pack.mkdir();
File progress = new File(pack, "save.dat");
try {
progress.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
//write file goes here
I can see folder structure in the app's folder
However if I change root to
File root=Environment.getExternalStorageDirectory();
no folders on the sdcard are created.Also I tried with this code:
File progress = new File(Environment.getExternalStorageDirectory(), "TestFolder");
if (!progress.exists()) {
progress.mkdir();
}
No success as well.
Manifest contains permission
android.permission.WRITE_EXTERNAL_STORAGE
UPD:Actually the last code does create new folder but this folder is in internal memory while I need it to be on sdcard
I have an auto update program for game launcher and I want to know how I can auto unzip all zip files on the same folder with launcher. (Multiple zip files are downloaded). I am a newbie when it comes to coding.
I need to change the following code for extracting all .zip files in the current folder where the app is.
using (var zip = Ionic.Zip.ZipFile.Read("desktop.zip"))
{
zip.ExtractAll(Directory.GetCurrentDirectory(), ExtractExistingFileAction.OverwriteSilently);
}
Try using Reflection:
using (var zip = Ionic.Zip.ZipFile.Read("desktop.zip"))
{
string exeFullPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
string exePath = System.IO.Path.GetDirectoryName(exeFullPath);
zip.ExtractAll(exePath
, ExtractExistingFileAction.OverwriteSilently);
}
#vendettamit is give me the correct answer. If someone need im going to post his code.
foreach (var file in Directory.EnumerateFiles("<directory path>", "*.zip"))
{
using (ZipFile zip = ZipFile.Read(file))
{
foreach (ZipEntry zipFiles in zip)
{
zipFiles.Extract(currentpath, true);
}
}
}
Do you know if there is any kind of tool (it would be cool if it is for free) that compares the file structure of a folder in a File Server to a SharePoint Online Document Library and tells you the difference?
The point is we are getting hands on a partially migrated File Server to SharePoint Online and the migration status of some folders is unknown to us. We already have a 3rd party migration tool to finish the migration but we need to know what is still pending to be uploaded. Any idea?
Thanks in advance.
We use sharegate for our migration. In your situation I might just run migrations on small sections with it set to "skip existing". That doesn't directly answer your question though.
In your case I would map both the File server and the SharePoint online instance as drives on a computer (using WebDAV) and hack together an app in your favorite language to compare the two directory structures.
Here is a java program that does that:
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
public class Launcher {
static PrintWriter fileOut;
public static void main(String[] args) throws IOException {
File fileStore = new File("N:\\"); //filestore dir top level
File sp = new File("M:\\");//sp directory top level (mapped)
File out = new File("C:\\Temp\\results.txt");
fileOut = new PrintWriter(out);
recurse(fileStore, sp);
fileOut.close();
}
private static void recurse(File dir1, File dir2)
{
File [] dirFiles;
if(dir2 == null)
dirFiles = new File[0];
else
dirFiles=dir2.listFiles();
File match;
for(File f1 : dir1.listFiles())
{
System.out.println(f1.getAbsolutePath());
match=null;
for(File f2:dirFiles)
if(f1.getName().equalsIgnoreCase(f2.getName()))
match=f2;
if(f1.isDirectory() && f1.canRead())
try{
recurse(f1,match);
}
catch(Exception e){}
else if (match == null)
fileOut.write(f1.getAbsolutePath()+"\r\n");
}
}
}
It writes to the given text file each file that is not in the 2nd directory structure.
You could run this code in an IDE like eclipse.
I'm trying to use the Html Agility Pack with a MonoTouch application, but cannot find a version that will work with it.
I downloaded the latest binaries from CodePlex and I've tried building with every DLL it contains. None will compile when the target is the iPhone.
Adding the .NET 20 library will allow it to compile to the iPhone Simulator, but when switching to the iPhone I get the error:
Error MT2002: Can not resolve reference: System.Diagnostics.TraceListener (MT2002) (MFLPlatinum12)
It seems like others are using HtmlAgilityPack with MonoTouch projects, so any thoughts as to what I'm missing?
Are you compiling from source or using the DLL directly?
You will need to make a new MonoTouch library project and add all the files for it to work.
Using a DLL directly likely won't work, since it was not compiled for MonoTouch.
You have to compile it from code
Download the source
go into
\htmlagilitypack-99964\Branches\1.4.0\HtmlAgilityPack
Edit the csproj change to
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
Save and load
Fix errors
Trace -> Debug
Remove block
if (!SecurityManager.IsGranted(new DnsPermission(PermissionState.Unrestricted)))
{
//do something.... not at full trust
try
{
RegistryKey reg = Registry.ClassesRoot;
reg = reg.OpenSubKey(extension, false);
if (reg != null) contentType = (string)reg.GetValue("", def);
}
catch (Exception)
{
contentType = def;
}
}
Remove block
if (SecurityManager.IsGranted(new RegistryPermission(PermissionState.Unrestricted)))
{
try
{
RegistryKey reg = Registry.ClassesRoot;
reg = reg.OpenSubKey(#"MIME\Database\Content Type\" + contentType, false);
if (reg != null) ext = (string)reg.GetValue("Extension", def);
}
catch (Exception)
{
ext = def;
}
}
Use the dll in the bin/debug folder