Jump to content

How to open a select file dialog?


55143681

Recommended Posts

Send file to Client

------------------------

procedure TFCONSULTAMOVINVENTARIOS.BTN_DownLoadXLSClick(Sender: TObject);
var
  Uid: TGuid;
  Result: HResult;
  W_recurso      :string;
  w_FileName     :string;
  FilesFolderPath:string;
  TempFolderPath :string;
  ExtFullPath    :string;
  w_Ruta         :string;
  ExcelName      :string;
begin
 ExtFullPath :=    UniServerModule.ExtFullPath  ;
 
// CREATE GUID PARA MANEJO DE ARCHIVO DE DATOS
  Result :=  CreateGuid(Uid);
  CreateGuid(Uid);
  if Result  = 1  then
    w_FileName:= GuidToString(Uid) ;
 
// ARMAR NOMBRE DE ARCHIVO PARA ENVIA AL FOLDER TEMPORAL
 // W_recurso := RECURSO.Text;
  w_FileName:=   w_FileName +  '.xls' ;
  w_Ruta    :=  UniServerModule.TempFolderPath + w_FileName ;
 
// CONVERTIR ARCHIVO A EXCEL , SALVARLO TEMPORALMENTE Y CREAR LINK DE DESCARGA
  uNativeXLSExport.DataSetToXLS(INMOV, w_Ruta );
 
  UniSession.SendFile(w_Ruta  , 'MovInventory.xls');
 
  LnkDowlaod.Caption:='<a href="'+ w_Ruta +'" target=new>Click here to download: ( '+' MovInventory.xls'+')</a>';
  LnkDowlaod.SetFocus;
 
end;
Link to comment
Share on other sites

 

Send file to Client

------------------------

procedure TFCONSULTAMOVINVENTARIOS.BTN_DownLoadXLSClick(Sender: TObject);
var
  Uid: TGuid;
  Result: HResult;
  W_recurso      :string;
  w_FileName     :string;
  FilesFolderPath:string;
  TempFolderPath :string;
  ExtFullPath    :string;
  w_Ruta         :string;
  ExcelName      :string;
begin
 ExtFullPath :=    UniServerModule.ExtFullPath  ;
 
// CREATE GUID PARA MANEJO DE ARCHIVO DE DATOS
  Result :=  CreateGuid(Uid);
  CreateGuid(Uid);
  if Result  = 1  then
    w_FileName:= GuidToString(Uid) ;
 
// ARMAR NOMBRE DE ARCHIVO PARA ENVIA AL FOLDER TEMPORAL
 // W_recurso := RECURSO.Text;
  w_FileName:=   w_FileName +  '.xls' ;
  w_Ruta    :=  UniServerModule.TempFolderPath + w_FileName ;
 
// CONVERTIR ARCHIVO A EXCEL , SALVARLO TEMPORALMENTE Y CREAR LINK DE DESCARGA
  uNativeXLSExport.DataSetToXLS(INMOV, w_Ruta );
 
  UniSession.SendFile(w_Ruta  , 'MovInventory.xls');
 
  LnkDowlaod.Caption:='<a href="'+ w_Ruta +'" target=new>Click here to download: ( '+' MovInventory.xls'+')</a>';
  LnkDowlaod.SetFocus;
 
end;

 

THANKS,I will my user can select where to save the file and can set the file name.and I know how to download the file.

Link to comment
Share on other sites

THANKS,I will my user can select where to save the file and can set the file name.and I know how to download the file.

 

You can only initiate a download. File save dialog depends on browser setting. In Chrome there is no option for this, other browsers have it.

Link to comment
Share on other sites

You can only initiate a download. File save dialog depends on browser setting. In Chrome there is no option for this, other browsers have it.

I wish my customers can select where to save file he want before download from server,I have put a saveDialog in the form,but when the the saveDialog is executed ,it display in the server ,not in the browser.

Link to comment
Share on other sites

could share uNativeXLSExport function

I use flexCel to download excel files,you should first produce the file in the server side,then download it.

//---------------------------------------------------------------------------
 
 
 
void __fastcall TUniFormFreeQuery::UniBitBtn10Click(TObject *Sender)
{
TExcelFile *xls = new TXlsFile(true);
__try
{
saveToExcel(xls);
}
__finally
{
delete xls;
}
}
//---------------------------------------------------------------------------
 
 
void __fastcall TUniFormFreeQuery::saveToExcel(TExcelFile *xls)
{
AnsiString destPath,destFile,tempFile;
int rowCount,colCount,i,j;
 
if(!UniQuery1->Active)
{
ShowMessage("先查询,再导出!");
return;
}
if(UniQuery1->RecordCount<1)
{
ShowMessage("没有记录,取消导出!");
return;
}
//
xls->NewFile(1);
 
rowCount=UniQuery1->RecordCount;
colCount=UniQuery1->FieldCount;
//写列头
i=1;
 
for(j=1;j<colCount;j++)
{
xls->SetCellValue(i, j, TCellValue::Create(UniQuery1->Fields->FieldByNumber(j)->FieldName));
}
//写数据
i=2;
while(!UniQuery1->Eof)
{
for(j=1;j<colCount;j++)
{
xls->SetCellValue(i, j, TCellValue::Create(UniQuery1->Fields->FieldByNumber(j)->AsString));
}
UniQuery1->Next();
i++;
}
 
xls->PrintLandscape = true;
 
tempFile="定制导出.xlsx";
destPath=UniServerModule()->FilesFolder+"临时文件\\下载表格\\"+UniMainModule()->loginUserNo+UniMainModule()->loginUserName;
//强制在服务端生成临时文件保存目录
if(!DirectoryExists(destPath))
{
ForceDirectories(destPath.c_str());
}
 
destFile=destPath+"\\"+tempFile;
//保存表格到服务器端的临时目录
xls->Save(destFile);
//选择本地保存目录和文件名
//if(!SaveDialog1->Execute() )  /*有问题,服务端显示*/
// return;
 
//浏览器端将服务器端默认临时表格文件下载保存成本地新名字
//UniSession->SendFile(destFile,SaveDialog1->FileName);
UniSession->SendFile(destFile);
 
 
}
Link to comment
Share on other sites

  • 2 years later...
20 hours ago, Oliver Morsch said:

You can use Microsoft Edge browser for example. It has a setting, so that the user will be asked what to do with the file (i.e. "save as ...").

Just as what you say,thanks.

Google,360...all support that.

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...