Mohd Saddaf khan
Mohd Saddaf khan

Reputation: 299

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

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.

Upvotes: 1

Views: 2665

Answers (1)

Jan B. Kjeldsen
Jan B. Kjeldsen

Reputation: 18051

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!
}

Upvotes: 1

Related Questions