I've been working on a way to embed attachments in my rvf files. I found a post on RVAttachedFile. I tried that but can't get it to work, it looks like the post is pretty old now. Did RVAttachedFile ever get updated?
What I'm doing now is using TNetEncoding base64. Here's what I'm using:
Code: Select all
//https://stackoverflow.com/questions/5795263/binary-to-base64-delphi
function TryEncodeFile(const AFileName: string; out ABase64string: string): Boolean;
var
MemStream: TMemoryStream;
begin
MemStream := TMemoryStream.Create;
try
MemStream.LoadFromFile(AFileName);
ABase64string :=
TNetEncoding.Base64.EncodeBytesToString(MemStream.Memory, MemStream.Size);
Result := True;
finally
MemStream.Free;
end;
end;
//https://stackoverflow.com/questions/6445089/how-to-convert-tbytes-to-binary-file-using-memorystream
procedure SaveBytesToFile(const Data: TBytes; const FileName: string);
var
Stream: TFileStream;
begin
Stream := TFileStream.Create(FileName, fmCreate);
try
if Data <> nil then
Stream.WriteBuffer(Data[0], Length(Data));
finally
Stream.Free;
end;
end;
Code: Select all
if TryEncodeFile( OpenDialog1.FileName, MimeFile ) then
begin
rve.DocProperties.Values[ 'att:' + ExtractFileName(OpenDialog1.FileName) ] := MimeFile;
rve.ApplyTextStyle(4); //jump
rve.InsertTextW(ExtractFileName(OpenDialog1.FileName));
rve.ApplyTextStyle(0); //normal
rve.InsertTextW(' '); //add trailing space
end;
Code: Select all
if rve.DocProperties.Values['att:' + rve.GetCurrentItemTextW] <> '' then
begin
Data := TNetEncoding.Base64.DecodeStringToBytes(rve.DocProperties.Values['att:' + rve.GetCurrentItemTextW]);
if Data = nil then exit;
SaveBytesToFile(Data,ExtractFilePath(Application.ExeName) + rve.GetCurrentItemTextW );
if FileExists(ExtractFilePath(Application.ExeName) + rve.GetCurrentItemTextW) then
ShellExecute(0,PChar('open'),
PChar(ExtractFilePath(Application.ExeName) + rve.GetCurrentItemTextW), nil, nil, SW_NORMAL );
end;
Have you ever gotten this working? And if so, do you have some code you can post?
Thanks Sergey
Stan