How to open text file with the help of button under any form? - axapta

I have one text file(Notepad) put under resources node in AX 2012 AOT. Now, my task is to open this file with the help of button under any form.
http://msdn.microsoft.com/en-us/library/cc967403.aspx
Above link is helpful when creating temporary file for writing or reading.
Also, there is a form in AX 2012 named "smmDocuments" in which we can put text files of our use and we can open that file easily from there. I have researched and found that there is a class named "DocuAction" in AX 2012 to perform operations with text files.
But I am unable to understand how that thing is working.
///////////////////
I got it working as:
void clicked()
{
//super();
str sTempPath,
sFileName = "notes.txt";
SysResource::saveToTempFile(SysResource::getResourceNode(resourceStr(flow_for_address_book_txt)), false, "notes.txt");
sTempPath = WinAPI::getTempPath();
WinAPI::shellExecute(sTempPath+sFileName);
}
Thanks Jan B.

You do not describe what actions you want to perform on your file.
Suppose you want to show the file to your user using the default program, then do:
void clicked()
{
SysResource::saveToTempFile(SysResource::getResourceNode(resourceStr(MyImage), false, "notes.txt");
WinAPI::shellExecute("notes.txt");
}
Use a temporary file instead of a hardcoded name.
You may also display the text in a form control:
void clicked()
{
container con = SysResource::getResourceNodeData(SysResource::getResourceNode(resourceStr(MyImage), false, "notes.txt");
infoStringControl.text(conpeek(con,1)); //Not sure how to use the container!
}

Related

How to upload client file to server?

I need to create form to upload file from client side to server in AX 2012 R3 using X++.
Can some one give me link / example regarding this issue?
I try to search and find that I can use class SysFileStoreManager, but still confused how to use it.
You can find example use of SysFileStoreManager using the Cross-reference Tool. I find it a bit bloated.
You can do this:
static client container getPackedFileClient(FileName _fileNameClient)
{
BinData binData = new BinData();
binData.loadFile(_fileNameClient);
return binData.getData();
}
This is the SysFileStoreManager.getPackedFileClient method, but without the protected keyword.
To save the file:
static server container saveFileToServer(container _packedFile, Filename _filename)
{
#File
BinData b = new BinData();
b.setData(_packedFile);
new FileIOPermission(_filename, #IO_WRITE).assert();
b.saveFile(_filename);
}
This is SysFileStoreManager.copyFileToClient_Client adapted for general use. You can the call the methods in sequence:
saveFileToServer(getPackedFileClient(clienFileName), serverFileName);
The file content is transferred from client to server using a container.

mvc 5 read and display text file content

I am trying to read a text file and display it on plage. This is what I did. But I am getting error
The process cannot access the file
'D:\wwwroot\TestProject\Logs\TestLog.log' because it is being used by
another process.
Controller Code
Array LogFileData = null;
var logFileNameWithPath = Server.MapPath("D:\wwwroot\TestProject\Logs\TestLog.log");
if (System.IO.File.Exists(logFileNameWithPath))
{
LogFileData = System.IO.File.ReadAllLines(logFileNameWithPath);
}
ViewBag.logFileContent = LogFileData;
View Code
#if (ViewBag.logFileContent != null)
{
foreach (string dataLine in ViewBag.logFileContent)
{
#dataLine
<br />
}
}
The log file is created and used by a service. My code works when I stop service. But I am not trying to write to file exclusively at the same time service is writing to it. Infact I am trying to read at a time when service is not writing to it. Any advice on how can I fix this? THanks.
Generally, you need to specify the "access mode" when you try to read the file. Please take a look here. Try to open the file into a FileStream with appropriate access.
I will post some code when I can.

Allow user to copy data from TableView

I have a simple JavaFX app that allows the user to query a database and see the data in a table.
I'd like to allow the user to be able to click a table cell and copy text from that cell to the clipboard with the standard clipboard key stroke: ctrl-c for Win/Linux or cmd-c for Mac. FYI, the text entry controls support basic copy/paste by default.
I'm using the standard javafx.scene.control.TableView class. Is there a simple way to enable cell copy? I did some searches and I see other people create custom menu commands... I don't want to create a custom menu, I just want basic keyboard copy to work with single cells.
I'm using single selection mode, but I can change to something else if need be:
TableView<Document> tableView = new TableView<Document>();
tableView.getSelectionModel().setCellSelectionEnabled(true);
tableView.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
You just have to create a listener in the scene, something like:
scene.getAccelerators()
.put(new KeyCodeCombination(KeyCode.C, KeyCombination.CONTROL_ANY), new Runnable() {
#Override
public void run() {
int row = table.getSelectionModel().getSelectedIndex();
DataRow tmp = table.getItems().get(row);
final Clipboard clipboard = Clipboard.getSystemClipboard();
final ClipboardContent content = new ClipboardContent();
if(table.getSelectionModel().isSelected(row, numColumn)){
System.out.println(tmp.getNumSlices());
content.putString(tmp.getNumSlices().toString());
}
else{
System.out.println(tmp.getSelected());
content.putString(tmp.getSelected());
}
clipboard.setContent(content);
}
});
For a complete example, you can download it at the gist.
I recommended that you review this post, work for me
http://respostas.guj.com.br/47439-habilitar-copypaste-tableview-funcionando-duvida-editar-funcionalidade
The author use an aditional util java class for enable the cell content copy from a tableView

How can I add a listview to a dialog via X++ code?

I'm creating a basic CSV importer tool. The goal is for a RunBase class to call a dialog, and in the dialog, I want to have the user select a CSV file that will be a specific format.
I have dialog.allowUpdateOnSelectCtrl(true) so the idea is when they choose a file, I can read in the first row and create a preview in a listview the same way as the Data Import/Export tool does.
This is all my dialog is so far:
public Object dialog()
{
DialogRunbase dialog = super();
container conFilter = ["Comma Seperated Value .txt ", "*.csv"];
#resAppl
;
dialog.filenameLookupFilter(conFilter);
dialog.allowUpdateOnSelectCtrl(true);
dlgFileName = dialog.addFieldValue(typeid(filenameSave),filenameSave);
return dialog;
}
I realize that I could create a custom form and other options. I'd like to try and do it this way so I can learn this method.

Axapta: Load and Save file from and to container field

I need to customize AX to load an arbitrary file with arbitrary size and save it to database as a container field. I also need to read back from that container field and write the content into a file, which should contain exactly the same file content as before load.
I had tried with BinaryIO, unfortunately with no luck
The answer to this question applies.
Especially you should use the system class BinData and the methods loadFile and saveFile
.
Example: this job copies the notepad program to a temporary directory.
static void BinDataTest(Args _args)
{
BinData b = new BinData();
Container c;
b.loadFile(#"C:\Windows\notepad.exe");
info(int2str(b.size()));
c = b.getData();
b = new BinData();
b.setData(c);
info(int2str(b.size()));
b.saveFile(#"C:\Temp\notepad.exe");
}

Resources