I have a Dialog asking for Preferences, in this Dialog I would like to aks for a path. I'm doing this: Dialog.addString("Saving directory", directory);
... I'm asking for lot more.
but I would like to have open up a new window, where you can search the path, like with this command but with more questions and answers in the Dialog.
path = File.openDialog("Select a File");
thank you
If you're using Fiji, you can try its GenericDialogPlus class, e.g. in Javascript:
importClass(Packages.fiji.util.gui.GenericDialogPlus);
gdp = new GenericDialogPlus("New dialog");
gdp.addDirectoryField("Directory", "/");
gdp.addCheckbox("Other option", true);
gdp.showDialog();
In plain ImageJ 1.x macro language, the preferred way of asking for directories and additional parameters is to have several consecutive dialogs. Use getDirectory("Choose a Directory") to ask for a directory, and use the Dialog functions to ask for other parameters:
path = getDirectory("Choose a Directory");
Dialog.create("Choose parameters");
Dialog.addString("Title:", title);
Dialog.show();
title = Dialog.getString();
print path;
print title;
Related
There are a lot posts about this subjects, but the link to any sloution are not working anymore... I followed this article.
I downloaded TCPDF master.
Upzipped it in the folder Vendor/ tcpdf
Eddited xtcpdf.php
<?php
App::import('Vendor','tcpdf/tcpdf');
class XTCPDF extends TCPDF{
}
Edit config.php (is this the right path?
/**
* Installation path (/var/www/tcpdf/).
* By default it is automatically calculated but you can also set it as a fixed string to improve performances.
*/
define ('K_PATH_MAIN', '/var/www/ppp/app/Vendor/tcpdf');
/**
* URL path to tcpdf installation folder (http://localhost/tcpdf/).
* By default it is automatically set but you can also set it as a fixed string to improve performances.
*/
define ('K_PATH_URL', 'http://localhost/ppp/Vendor/tcpdf');
Create app/View/Layouts/pdf/default.ctp
<?php
header("Content-type: application/pdf");
echo $content_for_layout;
?>
Then in the webpages controller:
public function newpdf(){
$users = $this->User->find('all');
$this->set(compact('users'));
$this->layout = '/pdf/default';
$this->render()->type('application/pdf');
}
and in de view/webcontroller
public function newpdf(){
$users = $this->User->find('all');
$this->set(compact('users'));
$this->layout = '/pdf/default';
$this->render()->type('application/pdf');
}
When i want to test it i get a blank page, without anything...
I made the function in Webpages. Is that all right? Or should I make the function somewhere else?
The path in the configuration file, I work on a localhost on linux. The path: /var/www/ppp/app/Vendor/tcpdf. Is that the right path?
The URL is set is http://localhost/ppp/app/Vendor/tcpdf Is that the right URL?
Thanks in advance
first of all did you checked whether the tcpdf is loaded or not
App::import('Vendor','tcpdf',array('file' => 'tcpdf/tcpdf.php'));
then on path where you want to put the pdf.It must be the real path
$path=realpath('../webroot/pdf/') . '/';
then initialize the tcpdf
$pdf= new tcpdf();
then set desired file options
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Your Name');
$pdf->SetTitle(title);
$pdf->SetSubject('TCPDF');
$pdf->SetKeywords(keywords);
// add a page
$pdf->AddPage();
then get the html which you want to convert to pdf
$html= $this->render('/Elements/Pdf');
write the html to pdf
$pdf->writeHTML($html, true, false, true, false, '');
then output it
$name='pdf.pdf';
$pdf->Output($path.$name, 'F');
Let me know if still have some issues.
I have kept a word document (.docx) in one of the project folders which I want to use as a template.
This template contains custom header and footer lines for user. I want to facilitate user to download his own data in word format. For this, I want to write a function which will accept user data and referring the template it will create a new word file replacing the place-holders in the template and then return the new file for download (without saving it to server). That means the template needs to be intact as template.
Following is what I am trying. I was able to replace the placeholder. However, I am not aware of how to give the created content as downloadable file to user. I do not want to save the new content again in the server as another word file.
public void GenerateWord(string userData)
{
string templateDoc = HttpContext.Current.Server.MapPath("~/App_Data/Template.docx");
// Open the new Package
Package pkg = Package.Open(templateDoc, FileMode.Open, FileAccess.ReadWrite);
// Specify the URI of the part to be read
Uri uri = new Uri("/word/document.xml", UriKind.Relative);
PackagePart part = pkg.GetPart(uri);
XmlDocument xmlMainXMLDoc = new XmlDocument();
xmlMainXMLDoc.Load(part.GetStream(FileMode.Open, FileAccess.Read));
xmlMainXMLDoc.InnerXml = ReplacePlaceHoldersInTemplate(userData, xmlMainXMLDoc.InnerXml);
// Open the stream to write document
StreamWriter partWrt = new StreamWriter(part.GetStream(FileMode.Open, FileAccess.Write));
xmlMainXMLDoc.Save(partWrt);
partWrt.Flush();
partWrt.Close();
pkg.Close();
}
private string ReplacePlaceHoldersInTemplate(string toReplace, string templateBody)
{
templateBody = templateBody.Replace("#myPlaceHolder#", toReplace);
return templateBody;
}
I believe that the below line is saving the contents in the template file itself, which I don't want.
xmlMainXMLDoc.Save(partWrt);
How should I modify this code which can return the new content as downloadable word file to user?
I found the solution Here!
This code allows me to read the template file and modify it as I want and then to send response as downloadable attachment.
I have path Manipulation problem. The following code is placed in Page_load method of ASPx page.
String rName = Request.QueryString["reportName"];
string path = "C:\\hari" + rName;
if (File.Exists(path))
{
File.Delete(path);
}
But Fortify scan report for the above sample code shows ‘Path Manipulation’ issue as high
Need help to modify above code so that it can pass fortify scan
Jackson is right, this is a direct File Path Manipulation vulnerability that can be fixed through indirect selection.
From your known directory, list all the files. Use the value coming from your own directory list, not the user-supplied value.
String rName = Request.QueryString["reportName"];
String knownPath = "C:\\hari";
DirectoryInfo di = new DirectoryInfo(knownPath);
FileInfo[] files = di.GetFiles(rName);
if (files.length > 0)
{
files[0].Delete();
}
I think the problem is that someone could spoof a request with reportName = "..\\Windows\\Something important" which is clearly a security flaw. You need to change your code so that it doesn't read a partial filename from the request query string.
.txt file looks like
Euro
US Dollar
Australian Dollar
Pounds Sterling
Swiss Franc
and so on.
I have tried things like XDocument and ObservableCollection but can't seem to get them to work.
I would rather not hard code so much into xaml.
thanks,
Assuming you're sending the file with the project (file Build action set to "Content"), here's what you need:
First, add a ListBox to the Page called CurrenciesListBox, then add this code on the page load event or constructor:
var xapResolver = new System.Xml.XmlXapResolver();
using (var currenciesStream = (Stream)xapResolver.GetEntity(new Uri("Currencies.txt", UriKind.RelativeOrAbsolute), "", typeof(Stream)))
{
using (var streamReader = new StreamReader(currenciesStream))
{
while (!streamReader.EndOfStream)
{
CurrenciesListBox.Items.Add(streamReader.ReadLine());
}
}
}
Remember to change the filename above to match your file!
This is for starter, there are better ways to do the job (using MVVM)!
I would like to write to the C:\windows\temp directory (or it's configured equivalent) inside my Firefox-addon.
https://developer.mozilla.org/en/FileGuide/FileWriting
Gives the impression that there are system independent names for these paths:
var file = IO.getFile("Desktop", "myinfo.txt");
var stream = IO.newOutputStream(file, "text");
stream.writeString("This is some text");
stream.close();
But I can't find any reference in the specified references, as to what "Desktop" points to. So that leaves me not knowing what exactly is referred to in the names given by the documentation.
How to I use IO.getFile() to open a file in the windows global temp folder?
See also Code snippets: File I/O on developer.mozilla.org. It answers your question (Matthew is right, it's "TmpD"), and provides many other file-related examples.
[edit] Oh, and does IO actually work for you? I thought it was unavailable. [edit2] I added a warning at the top of the pages I could find, that mention it.
The keys are described here.
I believe you want TmpD, which is listed here
// Writing stackoverflow.txt to TEMP dir
const { OS } = Cu.import("resource://gre/modules/osfile.jsm", {})
const path = OS.Path.join(OS.Constants.Path.tmpDir, "stackoverflow.txt")
OS.File.writeAtomic(path, "Hello, StackOverflow!", {
encoding: "utf-8",
tmpPath: "stackoverflow.txt.tmp", // it's not necessary but I'd recommend to use it
}).then(() => console.log(path, "has been written"))
// C:\Users\traxium\AppData\Local\Temp\stackoverflow.txt has been written
// Reading stackoverflow.txt from TEMP dir
const { OS } = Cu.import("resource://gre/modules/osfile.jsm", {})
const path = OS.Path.join(OS.Constants.Path.tmpDir, "stackoverflow.txt")
OS.File.read(path, { encoding: "utf-8" }).then(txt => console.log(txt))
// "Hello, StackOverflow!"