Following the example provided by microsoft for Directory::GetDirectory I came to this piece of code:
auto k = System::IO::Directory::GetDirectories(installpath);
auto dir = k->GetEnumerator();
while (dir->MoveNext())
{
String^ subdirectory = safe_cast<String^>(dir->Current);
MessageBox::Show(subdirectory);
}
which should list all directories in installpath, right? Well it doesn't appear to work! (no messagebox) How do I fix this?
note: installpath exists and has subdirectories
Oh, silly me !
Installpath was 1 folder deeper and had nothing in it !
Sorry for the inconvenience!
Related
I tried to open a locally stored pdf with xamarin.
example code:
var files = Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));
var filepath = "file://" + files[0];
if (File.Exists(filepath))
{
await Launcher.OpenAsync(filepath);
}
But the file does not open. The only message I get is (android device):
what do I miss?
EDIT
the variable filepath contains:
file:///data/user/0/com.companyname.scgapp_pdfhandler/files/.config/test.pdf
also tried
file://data/user/0/com.companyname.scgapp_pdfhandler/files/.config/test.pdf
does not help
Figured I would add my comment as an answer for easier visibility in case others run into it in the future.
Pass a OpenFileRequest object instead, if you use a string it has to be the correct uri scheme for it. I suspect the uri scheme you are passing to it isn't something that is understood by the system
I've got a problem with Xamarin.UITest, specifically screenshot feature. It is not working as expected.
I'm trying to copy "created" screenshot to another directory, but I get the following error:
Message: System.IO.FileNotFoundException : Could not find file
'C:\Program Files (x86)\Microsoft Visual
Studio\2017\Enterprise\Common7\IDE\screenshot-1.png'.
I'm using this piece of code to copy image file:
var screen = app.Screenshot("Welcome screen.");
screen.CopyTo(#"C:\Users\someuser\Desktop\screenshotTest.png");
How to specify first path/location for screenshots, because the original path probably needs admin privileges, that I don't have.
Screenshots saved with App.Screenshot() are located in your test project's directory: MyTestProject"\bin\Debug folder where the first screenshot is named screenshot-1.
Half solution to the problem: I downgraded NUnit from 3.11.0 to 2.7.0, so it works OK.
Use MoveTo() insted of CopyTo().
var screenshot = app.Screenshot($"{DateTime.Now}_{platform}");
screenshot.MoveTo($#"{Destination}\{screenshot.Name}.{screenshot.Extension}");
My screenshots are saving to C:\Users\username\AppData\Local\Temp
Try this code
[TearDown]
public void Teardown()
{
SaveScreenshotIfTestFails();
}
private void SaveScreenshotIfTestFails()
{
if (TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Failed)
{
var testName = TestContext.CurrentContext.Test.Name;
var filename = $"{testName}.png";
var file = app.Screenshot(testName);
var dir = file.DirectoryName;
File.Delete(dir + "\\" + filename);
file.MoveTo($"{testName}.png");
}
}
Screenshots are saved to the Current Directory. Change it via Directory.SetCurrentDirectory.
We've setup liferay to use JackRabbit as its document repository. Now what I'm trying to do is retrieve an specific document, and all I know about it is it's name, and sometimes the name of the folder it may be located in.
I know DLFileEntryLocalServiceUtil allows me to retrieve said document but requires me to have it's id before handing it over. My question is, how can I get the id of the file I'm looking for if all I have is the file name and it's location?
Below code snippet could help you,
FileEntry fileEntry = DLAppServiceUtil.getFileEntry(repositoryId, CREATED_FOLDER_ID, fileName);
In above, you have pass repositoryId could be equivalent to groupId which you can get it from themedisplay.getGroupId(), your folderId and fileName
you can get folderId by below code,
long FOLDER_ID = 0;
long repositoryId = themeDisplay.getScopeGroupId();
long parentFolderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
List<Folder> lFolder = DLAppServiceUtil.getFolders(repositoryId, parentFolderId);
for (Folder folder : lFolder)
{
if (folder.getName().equalsIgnoreCase(FOLDER_NAME))
{
FOLDER_ID = folder.getFolderId();
break;
}
}
Please let me know if it helps
This is a follow up question of Where is that file on my system?
Tons of questions and answers all over SO and the internet but I can't find any that gives an answer to this specific question.
All is default but I can't find the file itself,
IT'S NOT THERE.
Where/how gets |DataDirectory| defined?
Where is the file saved, does it even exist? If not, what is going on?
edit: The file isn't located at AppDomain.CurrentDomain.GetData("DataDirectory").ToString(); all (sqattered) answers tell me it should be. It must be somewhere as the debugger breaks nagging about the model unequals the table when I change the model. It's not there.
The |DataDirectory| isn't a file per se. A quote from a rather old MSDN article:
By default, the |DataDirectory| variable will be expanded as follow:
For applications placed in a directory on the user machine, this will be the app's (.exe) folder.
For apps running under ClickOnce, this will be a special data folder created by ClickOnce
For Web apps, this will be the App_Data folder
Under the hood, the value for |DataDirectory| simply comes from a property on the app domain. It is possible to change that value and override the default behavior by doing this:
AppDomain.CurrentDomain.SetData("DataDirectory", newpath)
A further quote regarding your schema inconsistencies:
One of the things to know when working with local database files is that they are treated as any other content files. For desktop projects, it means that by default, the database file will be copied to the output folder (aka bin) each time the project is built. After F5, here's what it would look like on disk
MyProject\Data.mdf
MyProject\MyApp.vb
MyProject\Bin\Debug\Data.mdf
MyProject\Bin\Debug\MyApp.exe
At design-time, MyProject\Data.mdf is used by the data tools. At run-time, the app will be using the database under the output folder. As a result of the copy, many people have the impression that the app did not save the data to the database file. In fact, this is simply because there are two copies of the data file involved. Same applies when looking at the schema/data through the database explorer. The tools are using the copy in the project, not the one in the bin folder.
The |datadirectory| algorithm is located in the System.Data.dll assembly, in the internal System.Data.Common.DbConnectionOptions class. Here it as displayed by ILSpy (note the source it's now available in the reference source repository: https://github.com/Microsoft/referencesource/blob/e458f8df6ded689323d4bd1a2a725ad32668aaec/System.Data.Entity/System/Data/EntityClient/DbConnectionOptions.cs):
internal static string ExpandDataDirectory(string keyword,
string value,
ref string datadir)
{
string text = null;
if (value != null &&
value.StartsWith("|datadirectory|", StringComparison.OrdinalIgnoreCase))
{
string text2 = datadir;
if (text2 == null)
{
// 1st step!
object data = AppDomain.CurrentDomain.GetData("DataDirectory");
text2 = (data as string);
if (data != null && text2 == null)
throw ADP.InvalidDataDirectory();
if (ADP.IsEmpty(text2))
{
// 2nd step!
text2 = AppDomain.CurrentDomain.BaseDirectory;
}
if (text2 == null)
{
text2 = "";
}
datadir = text2;
}
// 3rd step, checks and normalize
int length = "|datadirectory|".Length;
bool flag = 0 < text2.Length && text2[text2.Length - 1] == '\\';
bool flag2 = length < value.Length && value[length] == '\\';
if (!flag && !flag2)
{
text = text2 + '\\' + value.Substring(length);
}
else
{
if (flag && flag2)
{
text = text2 + value.Substring(length + 1);
}
else
{
text = text2 + value.Substring(length);
}
}
if (!ADP.GetFullPath(text).StartsWith(text2, StringComparison.Ordinal))
throw ADP.InvalidConnectionOptionValue(keyword);
}
return text;
}
So it looks in the current AppDomain data first (by default, there is no "DataDirectory" data defined I believe) and then gets to the current AppDomain base directory. The rest is mostly checks for path roots and paths normalization.
On the MSDN forum there is a similiar but simplified question about this, which says:
By default the |DataDirectory| points to your application folder (as you figured out yourself in the original question: to the App_Data).
Since is just a substitution path to your database, you can define the path yourself with the AppDomain.SetData.
I am looking to access all files in a local directory in a JBoss application. I can put the directory anywhere in my war including WEB-INF if necessary. I then want to access each file in the directory sequentially. In a normal application if the directory was in the run location I could do something like:
File f = new File("myDir");
if(f.isDirectory && f.list().length != 0)
{
for(String fileName : f.list())
{
//do Read-Only stuff with fileName
}
}
I'm looking for a best-practices solution, so if I'm going about this wrong then please point me to the right way to access an unknown set of resources.
First thing to note: you're only going to get this to work if you have an exploded WAR, or possibly if the servlet container explodes the WAR for you.
With that caveat in mind, you could use ServletContext.getRealPath() as your starting point. You'd need to know the name of at least one file in the webapp's root directory, and go from there:
String knownFilePath = servletContext.getRealPath("knownFile");
File webAppRootDir = new File(knownFilePath).getParentFile();
// and then as per the question
File f = webAppRootDir ;
if(f.isDirectory && f.list().length != 0)
{
for(String fileName : f.list())
{
//do Read-Only stuff with fileName
}
}
Getting hold of ServletContext is left as an exercise for the reader.