Hi All,
Some time ago I implemented drag and drop from browser to my VFP app. And it worked fairly well most of the time.
But recently I find more and more it's not working, and the issue is something to do with the image. I'm not clear on what the issue is.
For example, this image:
Fails when I drop it onto my image class on the form.
But this image:
From what I can tell the key difference is the name of the file is in the URL. So when I drag and drop the image, if it has a valid file name it works fine.
The first one fails, but if I drag and drop that image directly into a Windows Folder, Windows will give it a name (like "image" or "download" or "0" or something else). If I then drag and drop that image onto the control, it works fine.
What I'm seeking is, what is it that Windows folder can do with the drag and drop image that VFP isn't?
I'm fine if I can rename the file in the drop, but when I try to give it a name at the drop time, it fails with something like "file not available from URL" or something to that effect (I don't have the error on hand).
The two images above are just examples I found that break. They're not important on their own.
Is there some way I can "transform" the first dragged URL into some file that I can drop directly onto the form?
The OLEDragDrop Event code I have is:
*
The message boxes are just to alert that the drop of the image didn't work. I've built in on the right click the GETFILE() function, I drag the image to that, and then pick it in place, and then it adds it, but this is a lot of annoying steps for my users. They want to just drag and drop and be done with it.
Any ideas how to resolve this? The "internet" was not really present in the height of my FPW 2.6 days, so none of this existed, and I don't fully understand it still.
Thanks.
Best Regards,
Scott
MIET, MASHRAE, CDCP, CDCS, CDCE, CTDC, CTIA, ATS
"Everything should be made as simple as possible, and no simpler."
Some time ago I implemented drag and drop from browser to my VFP app. And it worked fairly well most of the time.
But recently I find more and more it's not working, and the issue is something to do with the image. I'm not clear on what the issue is.
For example, this image:
Fails when I drop it onto my image class on the form.
But this image:
From what I can tell the key difference is the name of the file is in the URL. So when I drag and drop the image, if it has a valid file name it works fine.
The first one fails, but if I drag and drop that image directly into a Windows Folder, Windows will give it a name (like "image" or "download" or "0" or something else). If I then drag and drop that image onto the control, it works fine.
What I'm seeking is, what is it that Windows folder can do with the drag and drop image that VFP isn't?
I'm fine if I can rename the file in the drop, but when I try to give it a name at the drop time, it fails with something like "file not available from URL" or something to that effect (I don't have the error on hand).
The two images above are just examples I found that break. They're not important on their own.
Is there some way I can "transform" the first dragged URL into some file that I can drop directly onto the form?
The OLEDragDrop Event code I have is:
Code:
LPARAMETERS oDataObject, nEffect, nButton, nShift, nXCoord, nYCoord
LOCAL aValues, i, cText, nOperation
*
* Creates the proper directory structure to store images in, otherwise the storage routines pitch a fit and won't save.
lcDirectoryString = "\DOCS\CERTS\"+ADDBS(ALLTRIM(STR(GLOBALCERT.CERTID)))
*
IF NOT DIRECTORY(SYS(5)+SYS(2003)+lcDirectoryString)
MD(SYS(5)+SYS(2003)+lcDirectoryString)
ENDIF
*
Thisform.LockScreen = .T.
DO CASE
CASE oDataObject.GetFormat(1) && Text - In this case from a URL
cText = oDataObject.GetData(1)
*-- Add the text as a new item in the list
This.AddItem(cText)
* Check to make sure the URL contains a file in it's expression. This will assume that the ".Ext" will be 4 characters from the end.
IF LEFT(RIGHT(cText,4),1) # "."
MESSAGEBOX("This file can not be moved directly from web page. Try saving it locally, and then adding with Right-Click",64)
RETURN
ENDIF
*
* We ahve a good file from the URL, so let's build the destination saves (one for file, one to update the table).
*
lcFileSave = SYS(5)+SYS(2003)+lcDirectoryString+ALLTRIM(GLOBALCERT.CERTCOMPANYNAME)+"-Cert"+RIGHT(cText,4)
lcFieldSave = ADDBS(lcDirectoryString)+ALLTRIM(GLOBALCERT.CERTCOMPANYNAME)+"-Cert"+RIGHT(cText,4)
*
lnSaveSuccess = STRTOFILE(ThisForm.oleInternet.OpenURL(cText,1),lcFileSave) && Leaving this here for now in case we switch methods back later.
*
IF lnSaveSuccess > 0
SELECT (ThisForm.ActiveDBF)
REPLACE GLOBALCERT.CERTIMAGE WITH lcFieldSave
*
IF NOT TABLEUPDATE()
WAIT WINDOW "Unable to Save"
TABLEREVERT()
ENDIF
ELSE
MESSAGEBOX("There was an unexpected problem, probably with the URL which prevented the image from being saved. "+;
"Try saving it locally, and then adding with Right-Click", 64)
ENDIF
*
CASE oDataObject.GetFormat(15) && Files CF_DROP
DIMENSION aValues[1]
oDataObject.GetData(15, @aValues )
*-- Add each filename as a new item in the list
FOR i = 1 to alen(aValues)
This.AddItem(aValues[m.i])
NEXT
*
cText = aValues(1)
lcFileSave = SYS(5)+SYS(2003)+lcDirectoryString+ALLTRIM(GLOBALCERT.CERTCOMPANYNAME)+"-Cert"+RIGHT(cText,4)
lcFieldSave = ADDBS(lcDirectoryString)+ALLTRIM(GLOBALCERT.CERTCOMPANYNAME)+"-Cert"+RIGHT(cText,4)
*
llStore = .F.
TRY
COPY FILE (cText) TO (lcFileSave)
llStore = .T.
CATCH
* something went wrong in copying the file. llStore is still .F.
ENDTRY
*
IF llStore
SELECT (ThisForm.ActiveDBF)
REPLACE GLOBALCERT.CERTIMAGE WITH lcFieldSave
*
IF NOT TABLEUPDATE()
WAIT WINDOW "Unable to Save"
TABLEREVERT()
ENDIF
ELSE
MESSAGEBOX("There was an undisclosed problem which prevented the image from being saved. Please retry later.")
ENDIF
ENDCASE
* ThisForm.Refresh()
Thisform.LockScreen = .F.
The message boxes are just to alert that the drop of the image didn't work. I've built in on the right click the GETFILE() function, I drag the image to that, and then pick it in place, and then it adds it, but this is a lot of annoying steps for my users. They want to just drag and drop and be done with it.
Any ideas how to resolve this? The "internet" was not really present in the height of my FPW 2.6 days, so none of this existed, and I don't fully understand it still.
Thanks.
Best Regards,
Scott
MIET, MASHRAE, CDCP, CDCS, CDCE, CTDC, CTIA, ATS
"Everything should be made as simple as possible, and no simpler."