Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Jan : Saving attachment problem D7/indy10.0.52
| Subject: | Saving attachment problem D7/indy10.0.52 |
| Posted by: | "Jacques" (jacques.no..@btinternet.com) |
| Date: | Sun, 22 Jan 2006 16:15:56 |
Hope someone can help me with this. Basically, whenever i try to save
attachment(s) by setting a directory in which to save them, i get an error
msg: Error saving attachment. Here's the code i use:
procedure TForm1.Button1Click(Sender: TObject);
var
intindex,tcount,I:integer;
Attachment: TIdAttachmentfile;
fn1,bod,fname,s,fn:string;
filen:tfilename;
begin
FAttachPath:='c:\attachments'; <--this causes the program to crash
pop1.Username := 'admin@jacquesnoah.co.uk';
pop1.Password := 'vHxpDe6H';
pop1.Host := 'mail.jacquesnoah.co.uk';
pop1.Connect;
msgcount:=pop1.CheckMessages;
if msgcount > 0 then //messages on server prepare to download
begin
pop1.Retrieve(1, Mess);
for I:= 0 to Pred(Mess.MessageParts.Count) do
begin
//is there a attachment
Attachment := TIdAttachmentfile(Mess.MessageParts.Items[I]);
SaveDialog1.FileName := FAttachPath +Attachment.Filename;
Attachment.SaveToFile(SaveDialog1.FileName);
end;
end;
If i try to set FAttachPath(which is a string variable) to something like
'c:\attachments' then i get the msg: 'Error saving attachment'. I
assume(perhaps mistakenly) that FAttachPath refers to the path into which to
save the attachmants? If i dont assign a directory path to 'FAttachPath'
then everything works fine, except it saves the files to the directory that
the exe resides in, and obviously i dont want them there.
I also tried changing this line : SaveDialog1.FileName := FAttachPath
+Attachment.Filename; to: SaveDialog1.FileName := 'c:\attachments'
+Attachment.Filename; but to no avail.
The thing is, that whenever i try to assign a directory to save the
attachments in, the program does not work at all. I also tried assigning a
initial dir to the savedialog component, this did not work either.
Soi'm fresh out of ideas. Any suggestions?
Thanks