Save file opened with navigateToURL - apache-flex

I'm using navigateToURL to open a PDF file generated by Jasper and it's working well. Now I was asked to send an email with the PDF file as an attachment. We are using Velocity to send emails in our application but, to send attachments, we have to have the file saved somewhere and have the info of the path and filename.
Is it possible to save to file opened by navigateToURL?
I'm using Flex SDK 4.9.1.
Thank you.

Are you using JasperExportManager.exportReportToPdfStream() method to show the PDF?
If so, try to use JasperExportManager.exportReportToPdfFile().
Then you can save the PDF at server.
JasperPrint jasperprint = JasperFillManager.fillReport(jasper, paramMap, con);
// Streaming pdf now?
response.setContentType("application/pdf");
JasperExportManager.exportReportToPdfStream(jasperprint, response.getOutputStream());
// Save the PDF somewhere.
JasperExportManager.exportReportToPdfFile(jasperprint, path);

Related

Opening a Pdf document in Adobe photoshop

I have a silverlight control to upload documents in my web page to share point. While I upload a document it is successfully uploaded. But when i try to open it by clicking on the document the pdf document uploaded opens in the redirected IE page.
I want that Pdf to be directly opened in Adobe Reader instead of redirecting it to open in an IE page.
Can anyone please suggest if this is a browser setting or I need some code for it?
Thanks
Yogesh
Response.Clear();
Response.ContentType = "application/pdf";
OBJ.Save(Response.OutputStream, File);
Response.AddHeader("content-disposition", "attachment;filename="
+ "abcd".ToString());
Response.Flush();
Response.End();
Above is the code for downloading it. If you are saving the file in DB then get the binary data or if you are saving it in a folder within your app, give the path.

Displaying Save File Dialog in Asp.net web page

I have a ASP.net page which writes a file to the local disk.
I want to present the user a Save File dialog box and allow him to set the path to the folder.
I know code like below can be used;
Response.Clear();
Response.ContentType = "text/csv";
Response.AddHeader( "Content-Disposition", "attachment;filename=\"report.csv\"" );
// write your CSV data to Response.OutputStream here
Response.End();
But it fixes filepath.
I need to capture the filepath that the user selects.
Is that possible in ASP.net?
Thanks.
it does not work like that from a web page, you have to initiate the download suggestiong a target file name then the user can override your suggested file name and select any folder or filename he likes and your content will be saved in that location.
you do nothing with a local path which only makes sense on the client machine on the server side of ASP.NET application.
I need to capture the filepath that the user selects. Is that possible
No. Your web server presents a file to the client, where the client has the option to save this file.
In what way would the path the client saves this file be interesting to the server?

ASP.NET - FileUplaod filename shows different path

I've put a FileUpload control onto my form. When client browses for a file and selects one I want to use that file as an attachment to my mail message. For this purpose I write:
Attachment attachment = new Attachment(fileUpload1.FileName);
mail.Attachments.Add(attachment);
I get an error that says:"Could not find file 'C:\Windows\SysWOW64\inetsrv\Water lilies.jpg'." The thing is the path to the file is different from the path in the client. How can I attach a file that is on the client's machine to a mail message?
Have a look at this http://imar.spaanjaars.com/412/sending-attachments-directly-from-a-fileupload-control
Server.MapPath should fix your problem.
Attachment attachment = new Attachment(Server.MapPath(fileUpload1.FileName));
The FileName property gives you just that - the name of the file, no path included. You're seeing inetsrv in the path because that's IIS' working directory. You will probably want to utilize the PostedFile property, which will handle saving for you:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload.postedfile.aspx

How to create a file on server and save it on server

I m creating a pdf file on the server using iTextSharp.
It is working fine prompting me to save everything is fine.
I have 2 scenario
1) I want to save this file on a location on server
2) I want to save this file in database
My Last line after finishing the code is
document.Close();
So can anyone guide me how can I do it
The following method will create a new file on the disk with a paragraph in it. You could easily modify it to your needs.
Before this will work you must ensue the directory you wish to save to has the correct permissions set. Whatever user account the Application Pool for the website is using will need write access to the folder. Set this in Windows Explorer, Right Click > Properties > Security Tab. This is well documented on the internet.
You can store the filename in the database in many different ways and then link to the file from your UI. I suggest starting with a simple ADO.Net tutorial
protected void CreateDoc(string filename)
{
Document document = new Document();
PdfWriter.GetInstance(document, new FileStream(filename, FileMode.Create));
document.Open();
document.Add(new Paragraph("Hello World!"));
document.Close();
}

Aspx file generation

I am working on an .aspx page.its to download a pdf that is generated in the aspx page.
.but when hosted in Amazon cloud i am getting the message.
"The process cannot access the file because it is being used by another process".
but on the subsequent invocation of the .aspx page i am getting the pdf .
The pdf file is being generated.
Asp.Net uses separeted threads for each request. Probably you use some shared resources to generate pdf and don't clean up them. Therefore parellel requests may fail.
Using block (or calling Dispose() directly) may help.
using (StreamReader reader = new StreamReader(#"C:\My Files\test.txt"))
{
..
}
Also make sure you don't open files with exclusive permissions like this:
FileStream fileStream = new FileStream("test.txt", FileMode.Open, FileAccess.ReadWrite, FileShare.None);

Resources