Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 02-18-2010, 09:20 AM
izia izia is offline
Junior Member
 
Join Date: Feb 2010
Posts: 7
Default Drag and Drop Outlook attachment into SQL

Hi!
I have a program with delphi; I drag and drop files from the desktop or another folder and I save them into a database in SQL.
Right now I am looking for something a little more complex and I am not able
to find a way to do it.
In just few words, I want to drag a file (in my case a PDF file) which is an
attachment to an email in Outlook 2007 client, drop it and save into the database in SQL.
I have looked for it in google, but anything I found works as I want to work.
┐Have anyone any ideas?

Thanks
Reply With Quote
  #2  
Old 02-18-2010, 01:22 PM
MrBaseball34 MrBaseball34 is offline
Senior Member
 
Join Date: Jan 2001
Posts: 7,260
Default

Where are you dropoping it, exactly?
__________________
MrBaseball34

Hook 'em Horns
2005 College Football National Champions
2005 College Baseball National Champions
Reply With Quote
  #3  
Old 02-18-2010, 01:44 PM
izia izia is offline
Junior Member
 
Join Date: Feb 2010
Posts: 7
Default

In a listbox
Reply With Quote
  #4  
Old 02-19-2010, 04:08 AM
MrBaseball34 MrBaseball34 is offline
Senior Member
 
Join Date: Jan 2001
Posts: 7,260
Default

I can't even get the drop cursor to show. Can you show *any* of your code?
__________________
MrBaseball34

Hook 'em Horns
2005 College Football National Champions
2005 College Baseball National Champions
Reply With Quote
  #5  
Old 02-19-2010, 07:56 AM
izia izia is offline
Junior Member
 
Join Date: Feb 2010
Posts: 7
Default

This is the code that works with "normal" files, not with outlook attachments.


Quote:
unit UnidadMenuPrincipal;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, shellapi, DMDocumentos, DB;

type
TformMenuPrincipal = class(TForm)
lsFicheros: TListBox;
Label1: TLabel;

//para arrastrar y soltar
procedure SoltarFichero (var Msg: TWMDropFiles); message WM_DROPFILES;
procedure FormCreate(Sender: TObject);

private
{ Private declarations }
public
{ Public declarations }
end;

var
formMenuPrincipal: TformMenuPrincipal;

implementation

{$R *.dfm}

procedure TformMenuPrincipal.SoltarFichero (var Msg : TWMDropFiles);
const
MAXFILENAME = 255;
var
cnt, fileCount : integer;
fileName : array [0..MAXFILENAME] of char;
fichero: string;
begin
try
begin

// how many files dropped?
fileCount := DragQueryFile(msg.Drop, $FFFFFFFF, fileName, MAXFILENAME) ;

// query for file names
for cnt := 0 to -1 + fileCount do
begin
DragQueryFile(msg.Drop, cnt, fileName, MAXFILENAME) ;

//do something with the file(s)
lsFicheros.Items.Add (fileName);

//Adjuntamos el fichero
fichero:= fileName;

DocumentosDM.QInsertar.Close;
DocumentosDM.QInsertar.Parameters.ParamByName('id' ).Value:=1;
DocumentosDM.QInsertar.Parameters.ParamByName('nom bre').Value:= ExtractFileName(fichero);
DocumentosDM.QInsertar.Parameters.ParamByName('enc argo').Value:= 'A 20070100001';
DocumentosDM.QInsertar.Parameters.ParamByName('tip o').Value:= 'postfirma';
DocumentosDM.QInsertar.Parameters.ParamByName('con tenido').LoadFromFile(fichero, ftBlob);
DocumentosDM.QInsertar.Parameters.ParamByName('fec ha').Value:=Now;
DocumentosDM.QInsertar.Parameters.ParamByName('cap itulo').Value:= 1;

DocumentosDM.QInsertar.ExecSQL;

end;

end;
finally
DragFinish(Msg.Drop); //finaliza arrastrar y soltar
end;

end;


procedure TformMenuPrincipal.FormCreate(Sender: TObject);
begin
//permitimos arrastrar y soltar
DragAcceptFiles(Handle, True);
end;

end.
And this is another code that I'm trying to work with outlook attachment, this code catch the name of the file but has an error with the content, and only catch the content of .txt, with pdf files fails.



Quote:

unit Main;

interface

uses
Windows, Classes, Controls, Forms, ExtCtrls, StdCtrls,
DragDrop, DropSource, DragDropFile, DropTarget, Graphics, ImgList, Menus,
ActnList;

type
(*
** This is a custom data format.
** The data format supports TFileContentsClipboardFormat and
** T*FileGroupDescritorClipboardFormat.
*)
TVirtualFileDataFormat = class(TCustomDataFormat)
private
FContents: AnsiString;
FFileName: string;
public
constructor Create(AOwner: TDragDropComponent); override;
function Assign(Source: TClipboardFormat): boolean; override;
function AssignTo(Dest: TClipboardFormat): boolean; override;
procedure Clear; override;
function HasData: boolean; override;
function NeedsData: boolean; override;
property FileName: string read FFileName write FFileName;
property Contents: AnsiString read FContents write FContents;
end;

TFormMain = class(TForm)
EditFilename: TEdit;
Label1: TLabel;
MemoContents: TMemo;
Label2: TLabel;
DropDummy1: TDropDummy;
Panel2: TPanel;
PanelDragDrop: TPanel;
Image1: TImage;
ImageList1: TImageList;
DropEmptySource1: TDropEmptySource;
DropEmptyTarget1: TDropEmptyTarget;
Label3: TLabel;
PopupMenu1: TPopupMenu;
MenuCopy: TMenuItem;
MenuPaste: TMenuItem;
ActionList1: TActionList;
ActionCopy: TAction;
ActionPaste: TAction;
procedure OnMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormCreate(Sender: TObject);
procedure DropFileTarget1Drop(Sender: TObject; ShiftState: TShiftState;
Point: TPoint; var Effect: Integer);
procedure ActionCopyExecute(Sender: TObject);
procedure ActionCopyUpdate(Sender: TObject);
procedure ActionPasteExecute(Sender: TObject);
procedure ActionPasteUpdate(Sender: TObject);
private
{ Private declarations }
FSourceDataFormat: TVirtualFileDataFormat;
FTargetDataFormat: TVirtualFileDataFormat;
public
{ Public declarations }
end;

var
FormMain: TFormMain;

implementation

{$R *.DFM}

uses
DragDropFormats,
ShlObj,
ComObj,
ActiveX,
SysUtils;

procedure TFormMain.FormCreate(Sender: TObject);
begin
// Add our own custom data format to the drag/drop components.
FSourceDataFormat := TVirtualFileDataFormat.Create(DropEmptySource1);
FTargetDataFormat := TVirtualFileDataFormat.Create(DropEmptyTarget1);
end;

procedure TFormMain.OnMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
// Ignore right mouse button so popup menu can be invoked
if (Button = mbLeft) and DragDetectPlus(Handle, Point(X,Y)) then
begin
// Transfer the file name and contents to the data format...
FSourceDataFormat.FileName := EditFileName.Text;
FSourceDataFormat.Contents := MemoContents.Lines.Text;

// ...and let it rip!
DropEmptySource1.Execute;
end;
end;

procedure TFormMain.ActionCopyExecute(Sender: TObject);
begin
// Transfer the file name and contents to the data format...
FSourceDataFormat.FileName := EditFileName.Text;
FSourceDataFormat.Contents := MemoContents.Lines.Text;

// ...and copy to clipboard.
DropEmptySource1.CopyToClipboard;
end;

procedure TFormMain.ActionCopyUpdate(Sender: TObject);
begin
TAction(Sender).Enabled := (EditFilename.Text <> '');
end;

procedure TFormMain.ActionPasteExecute(Sender: TObject);
begin
DropEmptyTarget1.PasteFromClipboard;
end;

procedure TFormMain.ActionPasteUpdate(Sender: TObject);

begin


MenuPaste.Enabled := DropEmptyTarget1.CanPasteFromClipboard;
end;

procedure TFormMain.DropFileTarget1Drop(Sender: TObject;
ShiftState: TShiftState; Point: TPoint; var Effect: Integer);
begin
// Transfer the file name and contents from the data format.
EditFileName.Text := FTargetDataFormat.FileName;

// Limit the amount of data to 32Kb. If someone drops a huge amount on data on
// us (e.g. the AsyncTransferSource demo which transfers 10Mb of data) we need
// to limit how much data we try to stuff into the poor memo field. Otherwise
// we could wait for hours before transfer was finished.
MemoContents.Lines.Text := Copy(FTargetDataFormat.Contents, 1, 1024*32);
end;


{ TVirtualFileDataFormat }

constructor TVirtualFileDataFormat.Create(AOwner: TDragDropComponent);
begin
inherited Create(AOwner);

// Add the "file group descriptor" and "file contents" clipboard formats to
// the data format's list of compatible formats.
// Note: This is normally done via TCustomDataFormat.RegisterCompatibleFormat,
// but since this data format is only used here, it is just as easy for us to
// add the formats manually.
CompatibleFormats.Add(TFileContentsClipboardFormat .Create);
CompatibleFormats.Add(TAnsiFileGroupDescriptorClip boardFormat.Create);
CompatibleFormats.Add(TUnicodeFileGroupDescriptorC lipboardFormat.Create);
end;

function TVirtualFileDataFormat.Assign(Source: TClipboardFormat): boolean;
begin
Result := True;

(*
** TFileContentsClipboardFormat
*)
if (Source is TFileContentsClipboardFormat) then
begin
FContents := TFileContentsClipboardFormat(Source).Data
end else
(*
** TAnsiFileGroupDescriptorClipboardFormat
*)
if (Source is TAnsiFileGroupDescriptorClipboardFormat) then
begin
if (TAnsiFileGroupDescriptorClipboardFormat(Source).C ount > 0) then
FFileName := TAnsiFileGroupDescriptorClipboardFormat(Source).Fi lenames[0];
end else
(*
** TUnicodeFileGroupDescriptorClipboardFormat
*)
if (Source is TUnicodeFileGroupDescriptorClipboardFormat) then
begin
if (TUnicodeFileGroupDescriptorClipboardFormat(Source ).Count > 0) then
FFileName := TUnicodeFileGroupDescriptorClipboardFormat(Source) .Filenames[0];
end else
(*
** None of the above...
*)
Result := inherited Assign(Source);
end;

function TVirtualFileDataFormat.AssignTo(Dest: TClipboardFormat): boolean;
begin
Result := True;

(*
** TFileContentsClipboardFormat
*)
if (Dest is TFileContentsClipboardFormat) then
begin
TFileContentsClipboardFormat(Dest).Data := FContents;
end else
(*
** TAnsiFileGroupDescriptorClipboardFormat
*)
if (Dest is TAnsiFileGroupDescriptorClipboardFormat) then
begin
TAnsiFileGroupDescriptorClipboardFormat(Dest).Coun t := 1;
TAnsiFileGroupDescriptorClipboardFormat(Dest).File names[0] := FFileName;
end else
(*
** TUnicodeFileGroupDescriptorClipboardFormat
*)
if (Dest is TUnicodeFileGroupDescriptorClipboardFormat) then
begin
TUnicodeFileGroupDescriptorClipboardFormat(Dest).C ount := 1;
TUnicodeFileGroupDescriptorClipboardFormat(Dest).F ilenames[0] := FFileName;
end else
(*
** None of the above...
*)
Result := inherited AssignTo(Dest);
end;

procedure TVirtualFileDataFormat.Clear;
begin
FFileName := '';
FContents := ''
end;

function TVirtualFileDataFormat.HasData: boolean;
begin
Result := (FFileName <> '');
end;

function TVirtualFileDataFormat.NeedsData: boolean;
begin
Result := (FFileName = '') or (FContents = '');
end;

end.
Have you any idea?
Reply With Quote
  #6  
Old 02-19-2010, 01:20 PM
MrBaseball34 MrBaseball34 is offline
Senior Member
 
Join Date: Jan 2001
Posts: 7,260
Default

Personally, I would get the Raize DropMaster controls to handle this. I wrote code to use it to do exactly what you are trying to do at a job last year.

http://www.raize.com/devtools/dropmaster/default.asp

This really is the simplest way. Outlook drag/drop is not trivial and I don't think it can be handled in the normal manner.
__________________
MrBaseball34

Hook 'em Horns
2005 College Football National Champions
2005 College Baseball National Champions
Reply With Quote
  #7  
Old 02-22-2010, 10:10 AM
izia izia is offline
Junior Member
 
Join Date: Feb 2010
Posts: 7
Default

I will take a look, thank you
Reply With Quote
Reply

Tags
attachment, drag, drop, outlook, stream

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 11:19 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2018, vBulletin Solutions, Inc.