How to upload client file to server? - axapta

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.

Related

Assigning content store using JAVA API

I had posting in alfresco hub , couldnt get solution yet.
I was trying to convert javascript API code to java API which move files to different content store(' storeB'). We have storeB defined in - 'content-store-selector-context.xml'. We are using Enterrprises version of Alfresco 5.2.
java script code as follows , - Works perfectly fine . its working code.
for each (var n in node.children) {
if (n.isDocument) {
//Apply script for moving files to DMS Store 01
n.removeAspect("cm:versionable");
n.addAspect("cm:storeSelector");
n.properties['cm:storeName'] = "storeB";
n.save();
}
}
Below is Java API Code - But this code is not moving files to 'storeB'. Is there anything i am missing ?
Is there any similiar method available in java APIs.
List<ChildAssociationRef> children = nodeService.getChildAssocs(dayFolderRef);
Map<QName, Serializable> aspectsProps = new HashMap<QName, Serializable>(1);
aspectsProps.put(ContentModel.PROP_STORE_NAME, "storeB");
LOG.info("Folder::" + dayFolderRef.getId());
LOG.info("Number of Subfolder to be moved is ::" + children.size());
for (ChildAssociationRef childAssoc : children) {
NodeRef childNodeRef = childAssoc.getChildRef();
if (ContentModel.TYPE_CONTENT.equals(nodeService.getType(childNodeRef))) {
LOG.info("Moving the file to secondary storae "+childNodeRef.getId());
nodeService.removeAspect(childNodeRef, ContentModel.ASPECT_VERSIONABLE);
nodeService.addAspect(childNodeRef, ContentModel.ASPECT_STORE_SELECTOR, aspectsProps);
}
}
I can see a save method is java script API. based on response recieved Alfresco forum , there is no save method in javascript API. Java API run in transactions , so will commit eventually . But i can see from DB using the below SQL -
SELECT count(*)
FROM alf_content_url
WHERE orphan_time IS NOT NULL;
the above SQL returns same count after executing the code , so no DB updates happening. Anything wrong ?
Any help , appreciated
Regards
Brijesh
I don't see why that would not work, are you positive you're even entering that method? Try adding the content store selector aspect with no properties map, then add the content store name property with setProperty method separately.

How do I parse specific data from a website within Codename One?

I have run into a road block developing my Codename One app. One of my classes in my project parses 3 specific html "td" elements from a website and saves the text to a string where I then input that text data into a Codename One multibutton. I originally used jSoup for this operation but soon realized that Codename One doesn't support 3rd party jar files so I used this method as shown below.
public void showOilPrice() {
if (current != null) {
current.show();
return;
}
WebBrowser b = new WebBrowser() {
#Override
public void onLoad(String url) {
BrowserComponent c = (BrowserComponent) this.getInternal();
JavascriptContext ctx = new JavascriptContext(c);
String wtiLast = (String) ctx.get("document.getElementById('pair_8849').childNodes[4].innerText");
String wtiPrev = (String) ctx.get("document.getElementById('pair_8849').childNodes[5].innerText");
String wtiChange = (String) ctx.get("document.getElementById('pair_8849').childNodes[8].innerText");
Form op = new Form("Oil Prices", new BoxLayout(BoxLayout.Y_AXIS));
MultiButton wti = new MultiButton("West Texas Intermediate");
Image icon = null;
Image emblem = null;
wti.setEmblem(emblem);
wti.setTextLine2("Current Price: " + wtiLast);
wti.setTextLine3("Previous: " + wtiPrev);
wti.setTextLine4("Change: " + wtiChange);
op.add(wti);
op.show();
}
};
b.setURL("https://sslcomrates.forexprostools.com/index.php?force_lang=1&pairs_ids=8833;8849;954867;8988;8861;8862;&header-text-color=%23FFFFFF&curr-name-color=%230059b0&inner-text-color=%23000000&green-text-color=%232A8215&green-background=%23B7F4C2&red-text-color=%23DC0001&red-background=%23FFE2E2&inner-border-color=%23CBCBCB&border-color=%23cbcbcb&bg1=%23F6F6F6&bg2=%23ffffff&open=show&last_update=show");
}
This method works in the simulator (and gives a "depreciated API" warning), but does not run when I submit my build online after signing. I have imported the parse4cn1 and cn1JSON libraries and have gone through a series of obstacles but I still receive a build error when I submit. I want to start fresh and use an alternative method if one exists. Is there a way that I can rewrite this segment of code without having to use these libraries? Maybe by using the XMLParser class?
The deprecation is for the WebBrowser class. You can use BrowserComponent directly so WebBrowser is redundant in this case.
I used XMLParser for this use case in the past. It should work with HTML as it was originally designed to show HTML.
It might also be possible to port JSoup to Codename One although I'm not sure about the scope of effort involved.
It's very possible that onLoad isn't invoked for a site you don't actually see rendered so the question is what specifically failed on the device?

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.

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");
}

How to make an HTTP request from SSIS?

I'm interested in knowing how I can make an HTTP call from SSIS. For example, I would like to be able to download a file from http://www.domain.com/resource.zip and record the datetime of the download and the destination of the file on the drive. I would also like to capture such attributes as file size and capture the date & time when the download completed.
You can make use of the namespace System.Net.WebClient to make the Http request with the help of Script Task in SSIS. Following example shows how this can be achieved. The example was created in SSIS 2008 R2.
Step-by-step process:
Create a new SSIS package and create two variables namely RemoteUri and LocalFolder. Set the variable RemoteUri with the value http://www.google.com/intl/en_com/images/srpr/logo1w.png. this is the image url of the logo on the Google's home page. Set the variable LocalFolder with the value C:\temp\. this is the path where we are going to save the content. Refer screenshot #1.
On the SSIS package, place a Script Task. Replace the Main() method within the script task with the code provided under the Script Task Code section. Refer screenshot #2.
Screenshot #3 shows that the path C:\temp\ is empty.
Screenshot #4 shows successful execution of the package.
Screenshot #5 shows that the content (in this case the logo image) has been downloaded to the local folder path.
Screenshot #6 shows that the code was tested to download a .zip file. To achieve this, the value of the variable RemoteUri was changed with the content url that needs to be downloaded.
Script task code:
C# code that can be used only in SSIS 2008 and above.
public void Main()
{
Variables varCollection = null;
Dts.VariableDispenser.LockForRead("User::RemoteUri");
Dts.VariableDispenser.LockForRead("User::LocalFolder");
Dts.VariableDispenser.GetVariables(ref varCollection);
System.Net.WebClient myWebClient = new System.Net.WebClient();
string webResource = varCollection["User::RemoteUri"].Value.ToString();
string fileName = varCollection["User::LocalFolder"].Value.ToString() + webResource.Substring(webResource.LastIndexOf('/') + 1);
myWebClient.DownloadFile(webResource, fileName);
Dts.TaskResult = (int)ScriptResults.Success;
}
Screenshot #1:
Screenshot #2:
Screenshot #3:
Screenshot #4:
Screenshot #5:
Screenshot #6:
Just an alternative for #user756519 script, not as fast, but more bulletproof
public void Main()
{
Variables varCollection = null;
Dts.VariableDispenser.LockForRead("User::RemoteUri");
Dts.VariableDispenser.LockForRead("User::LocalFolder");
Dts.VariableDispenser.GetVariables(ref varCollection);
System.Net.WebClient myWebClient = new System.Net.WebClient();
string webResource = varCollection["User::RemoteUri"].Value.ToString();
string fileName = varCollection["User::LocalFolder"].Value.ToString() + webResource.Substring(webResource.LastIndexOf('/') + 1);
byte[] data;
using (WebClient client = new WebClient())
{
data = client.DownloadData(webResource);
}
FileInfo file = new System.IO.FileInfo(fileName);
file.Directory.Create(); // If the directory already exists, this method does nothing.
File.WriteAllBytes(file.FullName, data);
Dts.TaskResult = (int)ScriptResults.Success;
}
This way, webClient doesn't stay hanging, and also you're not dependent on the previous existence of C:\Temp directory.
Other than that, great answer from #user756519, very detailed.
Here are a couple of options:
Third party tools such as CozyRoc or BlueSSIS.
Script Task with WebClient
Script Task with HTTP Connection Manager
Script Task Examples at:
http://microsoft-ssis.blogspot.com/2011/05/download-source-file-from-website-with.html

Resources