File download control - delete file without validation? - file-upload

Hello XPages programmers.
I work on a simple XPages File Library.
To achieve that i use FileUpload control with FileDownload control.
When i create a new file, i enter its name, and select a file.
I set that uploading a file won't activate a validation, so i can attach a file without a specified name. Additionally i set it to do fullrefresh, so uploading a file takes place in an instant and a file is visible in FileDownload control.
Problem occurs, when i want to delete that attachment using garbage icon of FileDownload - i can't set it to run without walidation.
Is there any workaround avaiable?
Any help will be appreciated.

I used the workaround Mark Leusink suggested - created a simmilar button (used image from filedownload control) and then set it for full refresh with process data without validation property.
Code in JSSS
function deleteAttachments()
{
var attList = dDocument.getAttachmentList("Document_Attachment");
for(var i=0; i<attList.size(); i++)
{
var att:String = attList[i];
dDocument.removeAttachment("Document_Attachment", att.getName() );
}
}
Surely it can be used for delete a specific attachment by getting attachment name from rowdata in a repeater and use DATASOURCE.removeAttachment method.
Thanks for your support!

Related

Cypress Uploading

describe ('Upload Test' , function(){
it('Upload Test' , function(){
cy.visit('https://document.online-convert.com/convert/csv-to-excel')
cy.get('#fileUploadButton').click()
const catalogue ='../integration/Example.csv';
cy.get('#file').attachFile(catalogue);
cy.get('#multifile-submit-button-main').click()
})
})
i tried to upload the csv file and click on convert it, At cypress test result it shows that the file have been uploaded but actually its not.
enter image description here
I hope you're using cypress-file-upload. Your file seems to be in the integration folder. I would suggest putting all the files required for Cypress tests inside cypress/fixtures folder and calling them as fixtures.
I would also higly suggest to use cypress-file-upload.
With it you can do it like that:
First, you get your input field for the file. Then you can use .attachFile to declare the source and give it a name
cy.get('.FileInput input[type=file]')
.attachFile({filePath: 'Example.csv', fileName});
There are a couple of events attached to the input that need to be fired after you attach the file.
The user will click the "Choose file" and the OS opens a file selection dialog. Since Cypress can't control that dialog, you are effective replacing that step with .attachFile(...).
As soon as the file is attached, the upload begins automatically and when complete, the file name appears in the file list element.
The element we need to attach to is <input id="fileUploadInput" type="file">.
If you inspect this element, and look at it's event listeners there's a change event and a custom event fileuploadsubmit that look useful
This is the code that works for me
const catalogue = "../fixtures/example.csv";
cy.get('#fileUploadInput')
.attachFile(catalogue)
// this just confirms the internal file property of the element
// i.e confirm the attachFile worked
// You can leave it out, it does not affect the process
cy.get('#fileUploadInput')
.its('0.files')
.its('0')
.its('name')
.should('eq', 'example.csv')
// Now trigger the change event
cy.get('#fileUploadInput')
.trigger('change', {force:true}) // force because the input is hidden
// And the fileuploadsubmit event
// Note that after change event, the input is detached from DOM
// so we need to re-query for the id
cy.get('#fileUploadInput')
.trigger('fileuploadsubmit', {force:true})
// Confirm the file is in the file list
// if it's a large file, allow enough time with a timeout option
cy.contains('span', 'example.csv', {timeout: 10000})
// Now start the conversion
cy.get('#multifile-submit-button-main').click()

Place Equipment From Ribbon Revit 2015: Transaction already started

Stack,
I'm programming an external application that works in Autodesk's Revit (2015). I've created a button on the ribbon that allows the user to place a special equipment that I'll use later to read and pass on to another process. I using 'TheBuildingCoder's' 'Family API' examples to do so. The button on the ribbon has an external command set in the .addin file in the ProgramData Directory...
<AddIn Type="Command">
<Assembly>C:\GSN Programs\MyDll.dll</Assembly>
<AddInId>{97715E4F-EA48-4690-8C62-B5D4836FF452}</AddInId>
<FullClassName>RcarsPlugIn.PlaceEquipment</FullClassName>
<VendorId>MyCompany, LLC</VendorId>
<Text>Place Equipment</Text>
<VisibilityMode>AlwaysVisible</VisibilityMode>
<Discipline>Any</Discipline>
<LanguageType>Unknown</LanguageType>
</AddIn>
On the button press, I put the command data into a global variable to use throughout the program...
If IsNothing(gv_oGo) Then
gv_oGo = New clsGeneralOperations
gv_oGo.CachedCommandData = exCommandData
gv_oGo.UiApp = exCommandData.Application.ActiveUIDocument.Application
End If
With the CommandData cached I move to place the equipment by user pick...
uiDoc = gv_oGo.UiApp.ActiveUIDocument
oSym = oRF.FindElement(doc, GetType(FamilySymbol), "MyEQUIP")
uiDoc.PromptForFamilyInstancePlacement(oSym)
Public Function FindElement(doc As Document, targetType As Type, sTargetName As String) As Element
Return New FilteredElementCollector(doc).OfClass(targetType).FirstOrDefault(Function(e) e.Name.Equals(sTargetName))
End Function
That's where the problem comes into play. I get an error message sent back from Revit stating that "Placement is not permitted in an already modifiable document. The active transaction must be closed first." The problem is, I haven't started a different transaction. The button onthe ribbon is the first that touched when Revit starts.
Is there a way to loop through the open transactions and find one that is open? Is the document in some state that I don't understand? I'm not sure which direction to turn here... any help would be appreciated.
Thanks,
Runnin...
Ok, one clarifying question - the exception is occurring on
uiDoc.PromptForFamilyInstancePlacement(oSym) line correct? if so, try using a subtransaction to complete your command instead:
Document doc = uiDoc.Document;
using (SubTransaction subtr_fam = new SubTransaction(doc))
{
try
{
uiDoc.PromptForFamilyInstancePlacement(oSym);
}
catch(Exception e)
{
Console.WriteLine(e.StackTrace.ToString());
}
}

Override the upload function of a file upload control

I want to override the upload function of a file upload control in order to add the functionality that I need. I am trying to adapt the code from the following link to my case
Auto-save doc after delete of attachment in File Download control?
by changing the type of the second parameter to com.ibm.xsp.component.xp.XSPFileUpload, i.e.:
function rekOverrideFileDownloadAction( component:javax.faces.component.UIOutput, fDownload:com.ibm.xsp.component.xp.XSPFileUpload ){
and the code in the MethodBinding mBinding and by using the name of my file upload control, i.e.:
var mBinding = facesContext.getApplication().createMethodBinding("#{javascript:print('Uploaded');}", null );
overrideFileDownloadAction( getComponent( 'fileUpload1' ) );
Unfortunately, a javax.faces.FacesException occurs.
Can anyone help me to modify this code in order to just print this message when the user uploads a file?
Stack Trace:
javax.faces.FacesException
javax.faces.FacesException.<init>(FacesException.java:97)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:86)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:210)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:96)
com.ibm.xsp.controller.FacesControllerImpl.execute(FacesControllerImpl.java:250)
com.ibm.xsp.webapp.FacesServlet.serviceView(FacesServlet.java:209)
com.ibm.xsp.webapp.FacesServletEx.serviceView(FacesServletEx.java:204)
com.ibm.xsp.webapp.FacesServlet.service(FacesServlet.java:160)
com.ibm.xsp.webapp.FacesServletEx.service(FacesServletEx.java:138)
com.ibm.xsp.webapp.DesignerFacesServlet.service(DesignerFacesServlet.java:103)
com.ibm.designer.runtime.domino.adapter.ComponentModule.invokeServlet(ComponentModule.java:576)
com.ibm.domino.xsp.module.nsf.NSFComponentModule.invokeServlet(NSFComponentModule.java:1281)
com.ibm.designer.runtime.domino.adapter.ComponentModule$AdapterInvoker.invokeServlet(ComponentModule.java:847)
com.ibm.designer.runtime.domino.adapter.ComponentModule$ServletInvoker.doService(ComponentModule.java:796)
com.ibm.designer.runtime.domino.adapter.ComponentModule.doService(ComponentModule.java:565)
com.ibm.domino.xsp.module.nsf.NSFComponentModule.doService(NSFComponentModule.java:1265)
com.ibm.domino.xsp.module.nsf.NSFService.doServiceInternal(NSFService.java:653)
com.ibm.domino.xsp.module.nsf.NSFService.doService(NSFService.java:476)
com.ibm.designer.runtime.domino.adapter.LCDEnvironment.doService(LCDEnvironment.java:341)
com.ibm.designer.runtime.domino.adapter.LCDEnvironment.service(LCDEnvironment.java:297)
com.ibm.domino.xsp.bridge.http.engine.XspCmdManager.service(XspCmdManager.java:272)
java.lang.NullPointerException
com.ibm.xsp.actions.ActionGroup.invoke(ActionGroup.java:135)
com.ibm.xsp.actions.ActionGroup.invoke(ActionGroup.java:135)
com.ibm.xsp.application.ActionListenerImpl.processAction(ActionListenerImpl.java:60)
javax.faces.component.UICommand.broadcast(UICommand.java:324)
com.ibm.xsp.component.UIEventHandler.broadcast(UIEventHandler.java:366)
com.ibm.xsp.component.UIViewRootEx.broadcast(UIViewRootEx.java:1535)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:307)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:428)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:94)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:210)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:96)
com.ibm.xsp.controller.FacesControllerImpl.execute(FacesControllerImpl.java:250)
com.ibm.xsp.webapp.FacesServlet.serviceView(FacesServlet.java:209)
com.ibm.xsp.webapp.FacesServletEx.serviceView(FacesServletEx.java:204)
com.ibm.xsp.webapp.FacesServlet.service(FacesServlet.java:160)
com.ibm.xsp.webapp.FacesServletEx.service(FacesServletEx.java:138)
com.ibm.xsp.webapp.DesignerFacesServlet.service(DesignerFacesServlet.java:103)
com.ibm.designer.runtime.domino.adapter.ComponentModule.invokeServlet(ComponentModule.java:576)
com.ibm.domino.xsp.module.nsf.NSFComponentModule.invokeServlet(NSFComponentModule.java:1281)
com.ibm.designer.runtime.domino.adapter.ComponentModule$AdapterInvoker.invokeServlet(ComponentModule.java:847)
com.ibm.designer.runtime.domino.adapter.ComponentModule$ServletInvoker.doService(ComponentModule.java:796)
com.ibm.designer.runtime.domino.adapter.ComponentModule.doService(ComponentModule.java:565)
com.ibm.domino.xsp.module.nsf.NSFComponentModule.doService(NSFComponentModule.java:1265)
com.ibm.domino.xsp.module.nsf.NSFService.doServiceInternal(NSFService.java:653)
com.ibm.domino.xsp.module.nsf.NSFService.doService(NSFService.java:476)
com.ibm.designer.runtime.domino.adapter.LCDEnvironment.doService(LCDEnvironment.java:341)
com.ibm.designer.runtime.domino.adapter.LCDEnvironment.service(LCDEnvironment.java:297)
com.ibm.domino.xsp.bridge.http.engine.XspCmdManager.service(XspCmdManager.java:272)
I also noticed that if I add a script to an event, e.g. onChange, so that an event handler is created no exception occurs. So I think the exception is thrown because there is no event handler and that leads to a null pointer. For now I have added the functionality I need to the onChange event and it is ok, but it would be nice if someone could tell me if there is a way to override it.
Thank you in advance!
What are you trying to do? I think that it is not possibile with the snippet (it overwrites an event handler of the download link which is available for an Upload Control only).
Maybe this snippet can help you: http://openntf.org/XSnippets.nsf/snippet.xsp?id=replace-attachment-when-uploading-a-new-attachment

Photoshop: get slices via SDK and copy content

I want to copy the content of the current seleced slice in my photoshop cs3 document to a new document using an own written script/plugin.
Currently, I do this manually: I select the slice, press ctrl+c (copy), create a new document and then I press ctrl+v (paste).
What I have so far is the automation plugin example 'MakeNew' that creates a new document:
static SPErr MakeNewDocument (void)
{
SPErr error = kSPNoError;
PIActionDescriptor descriptor = NULL;
error = sPSActionDescriptor->Make (&descriptor);
...
}
Any Idea how I can access the current selected slice and copy the content to the new document?
Thanks for hints.
Looks like there is no way to get the slices even via SDK in CS3.

How to link a PDF Document to a Record using Visual Studio LightSwitch 2011?

I'm Stuck the following problem: How can I link a PDF Document to a Record in a Data Grid using Visual Studio LightSwitch 2011 and Visual Basic?
Any help would be awesome, thanks!
Here's the simplest way to do this: add a custom command to the Command Bar of the Data Grid Row for your Data Grid. In this example I'm calling the command Open PDF File. Then add this code to Execute code for the command:
partial void OpenPDFFile_Execute()
{
const string LOCAL_SERVER_PDF_DIR = #"\\MyServer\PDFs\";
const string WEB_SERVER_PDF_DIR = "http://myweb.server/PDFs/";
const string PDF_SUFFIX = ".pdf"; //assumes you do not include the extension in the db field value
if (AutomationFactory.IsAvailable)
{
//if the AutomationFactory is available, this is a desktop deployment
//use the shell to open a PDF file from the local network
dynamic shell = AutomationFactory.CreateObject("Shell.Application");
string filePath = LOCAL_SERVER_PDF_DIR + this.PDFFiles.SelectedItem.FileName + PDF_SUFFIX;
shell.ShellExecute(filePath);
}
else
{
//otherwise this must be a web deployment
//in order to make this work you must add a reference to System.Windows.Browser
//to the Client project of your LS solution
var uri = new Uri(WEB_SERVER_PDF_DIR + this.PDFFiles.SelectedItem.FileName + PDF_SUFFIX);
HtmlPage.Window.Navigate(uri, "_blank");
}
}
You will need to add the following imports to the top of your user code file to make this code compile:
using System.Runtime.InteropServices.Automation;
using System.Windows.Browser;
I should mention that you need a directory to server the PDFs up from. This example is flexible with respect to deployment, because it handles both desktop and web configurations. Since you'll need to set up the PDF directoy, you may want to just handle one configuration option to simply things (or you could expose the same PDF directory over http and as a local network share).
You may also want to present this as a true link instead of a button. In order to do this, you'll need a custom SilverLight control. In any case, I would recommend implementing the PDF link using a button first. You can then move this same code to a link event handler as a separate project if that is worth spending time on.