Focal Point Banner


As of December 1, 2020, Focal Point is retired and repurposed as a reference repository. We value the wealth of knowledge that's been shared here over the years. You'll continue to have access to this treasure trove of knowledge, for search purposes only.

Join the TIBCO Community
TIBCO Community is a collaborative space for users to share knowledge and support one another in making the best use of TIBCO products and services. There are several TIBCO WebFOCUS resources in the community.

  • From the Home page, select Predict: WebFOCUS to view articles, questions, and trending articles.
  • Select Products from the top navigation bar, scroll, and then select the TIBCO WebFOCUS product page to view product overview, articles, and discussions.
  • Request access to the private WebFOCUS User Group (login required) to network with fellow members.

Former myibi community members should have received an email on 8/3/22 to activate their user accounts to join the community. Check your Spam folder for the email. Please get in touch with us at community@tibco.com for further assistance. Reference the community FAQ to learn more about the community.


Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED]How to change the suggested name of the file to be saved

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[SOLVED]How to change the suggested name of the file to be saved
 Login/Join
 
<JJI>
posted
Hi,

I have created a flat file that I can successfully hold, with the name and the extension I want, on the reporting server by using a FILEDEF and an ON TABLE SAVE.

EX. FILEDEF TEST DISK D:\IBI\APPS\TESTSITE\test.dta

The problem is that the user needs a mapping to the reporting server to be able to see the file.

As an alternatif I tried: ON TABLE PCHOLD FORMAT ALPHA which prompt the user to save the file. But, the suggested name is something like WFServlet8a6c4dbe (random generated by WF) and no extention. I would like it to be test.dta (name+extention). The name and the extention is important as the file need to be sent to the government

Is this possible?
If not is their a way to save the file directly on the disk of the user by using a dynamic FILEDEF (EX. FILEDEF TEST DISK &Destination).
All suggestions are welcome.

Kind regards,

This message has been edited. Last edited by: <JJI>,
 
Report This Post
Expert
posted Hide Post
As far as I am aware, you cannot name the file returning.

You also cannot have the reporting server hold a file to the clients directory.

If the server has access to a network location that the user has access to, then it could be put there.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

 
Posts: 6347 | Location: 33°49'23.0"S, 151°11'41.0"E | Registered: October 31, 2006Report This Post
<JG>
posted
On an IIS based system I use ASP to download the generated file which has to be held in a permanant location on the server.

As you are on Tomcat then you could use JSP to do the same thing.

Here's the ASP method.

The focexec
  
-SET &FILENAME='C:\temp\car.txt';
FILEDEF CARTEXT DISK &FILENAME
-RUN
TABLE FILE CAR
PRINT COUNTRY CAR MODEL
ON TABLE SAVE AS CARTEXT
END
-RUN
-HTMLFORM BEGIN
<HTML>
<head>
</head>
<BODY onLoad="javascript:document.f1.submit();">
<FORM name="f1" METHOD="POST" ACTION="/approot/baseapp/download.asp?file=!IBI.AMP.FILENAME;">
</FORM>
</BODY>
</HTML>
-HTMLFORM END


The ASP code
  
<%@Language="VBScript"%>
<%Option Explicit%>
<%Response.Buffer = True%>
<%
On Error Resume Next
Dim strPath
strPath = CStr(Request.QueryString("file"))
If strPath = "" Then
	Response.Clear
	Response.Write("No file specified.")
	Response.End
ElseIf InStr(strPath, "..") > 0 Then
	Response.Clear
	Response.Write("Illegal folder location.")
	Response.End
ElseIf Len(strPath) > 1024 Then
	Response.Clear
	Response.Write("Folder path too long.")
	Response.End
Else
	Call DownloadFile(strPath)
End If

Private Sub DownloadFile(file)
	'--declare variables
	Dim strAbsFile
	Dim strFileExtension
	Dim objFSO
	Dim objFile
	Dim objStream
	strAbsFile = Server.MapPath(file)
	Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
	If objFSO.FileExists(strAbsFile) Then
		Set objFile = objFSO.GetFile(strAbsFile)
		'-- first clear the response, and then set the appropriate headers
		Response.Clear
		'-- the filename you give it will be the one that is shown
		' to the users by default when they save
		Response.AddHeader "Content-Disposition", "attachment; filename=" & objFile.Name
		Response.AddHeader "Content-Length", objFile.Size
		Response.ContentType = "application/octet-stream"
		Set objStream = Server.CreateObject("ADODB.Stream")
		objStream.Open
		'-- set as binary
		objStream.Type = 1
		Response.CharSet = "UTF-8"
		'-- load into the stream the file
		objStream.LoadFromFile(strAbsFile)
		'-- send the stream in the response
		Response.BinaryWrite(objStream.Read)
		objStream.Close
	         Set objStream = Nothing
		Set objFile = Nothing
	Else 'objFSO.FileExists(strAbsFile)
		Response.Clear
		Response.Write("No such file exists.")
		Set objFSO = Nothing
	End If

End Sub
%>


This is set up to handle binary files but you can process ASCII by switching objStream.Type
 
Report This Post
Platinum Member
posted Hide Post
We do something similar however we have the filedef point the file to a network share using the UNC name we then have created a dashboard that points to the share. We do this as we have reports being ran from multiple systems and this allows them to be written to the same place. Not sure if this would work in your situation.


Webfocus 8.0.7 on Windows
 
Posts: 176 | Location: Ohio | Registered: October 26, 2006Report This Post
<JG>
posted
Here is a JSP version that does the same thing so it works with Tomcat etc.

The procedure

  
-SET &DOSPATH='c:\temp\';
-SET &JSPPATH=STRREP (&DOSPATH.LENGTH, &DOSPATH, 1, '\', 2,'//', 80, 'A80');
-SET &JSPPATH=TRUNCATE(&JSPPATH);
-SET &FILE='carx';
-SET &FILENAME='&FILE.EVAL.txt';
FILEDEF &FILE.EVAL DISK &DOSPATH.EVAL&FILENAME.EVAL
-RUN
TABLE FILE CAR
PRINT COUNTRY CAR MODEL
ON TABLE SAVE AS &FILE.EVAL
END
-RUN
-HTMLFORM BEGIN
<HTML>
<head>
</head>
<BODY onLoad="javascript:document.f1.submit();">
<FORM name="f1" METHOD="POST" ACTION="/approot/baseapp/download.jsp?file=!IBI.AMP.FILENAME;&|PATH=!IBI.AMP.JSPPATH;">
</FORM>
</BODY>
</HTML>
-HTMLFORM END


The code for download.jsp

  
<%@ page  import="java.io.FileInputStream" %>
<%@ page  import="java.io.BufferedInputStream"  %>
<%@ page  import="java.io.File"  %>
<%@ page import="java.io.IOException" %>

<%   
   String filename=request.getParameter("file");
   String filepath=request.getParameter("PATH");

BufferedInputStream buf=null;
   ServletOutputStream myOut=null;

try{

myOut = response.getOutputStream( );
     File myfile = new File(filepath+filename);
     
     //set response headers
     response.setContentType("text/plain");
      
     response.addHeader(
        "Content-Disposition","attachment; filename="+filename );

     response.setContentLength( (int) myfile.length( ) );
      
     FileInputStream input = new FileInputStream(myfile);
     buf = new BufferedInputStream(input);
     int readBytes = 0;

     //read from the file; write to the ServletOutputStream
     while((readBytes = buf.read( )) != -1)
       myOut.write(readBytes);

} catch (IOException ioe){
     
        throw new ServletException(ioe.getMessage( ));
         
     } finally {
         
     //close the input/output streams
         if (myOut != null)
             myOut.close( );
          if (buf != null)
          buf.close( );
         
     }   
%>


Have fun.

Oh by the way yes it will work on unix based server environments but you may have to use sed to convert
the UNIX line feeds to Windows carriage return/line feeds before the file can be used.

This message has been edited. Last edited by: <JG>,
 
Report This Post
<JJI>
posted
Hi guys,

Thanks for your idea's and solutions. I'm going to try the jsp solution on Monday.

Ci@o
 
Report This Post
<JG>
posted
Dirk, Just a note on a possible issue, You said that you wanted a file extension of .DTA

I've tested it and there is no problem correctly saving the file.

However by default .DTA does not have a file association in Windows so if you want to be able to open
the file automatically in notepad or another text editor then you will have to manually select the
application to open the file with. Should only need to do it the first time though.
 
Report This Post
<JJI>
posted
Hi JG,

I was awear of this issue, but thanks for the reminder. I almost forgot about it. Many thanks for your help. It works perfectly

Kind regards,
 
Report This Post
  Powered by Social Strata  

Read-Only Read-Only Topic

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED]How to change the suggested name of the file to be saved

Copyright © 1996-2020 Information Builders