Link to open a PDF file that's saved in a folder? - c#

Hi there. I think this one is a tough one, but I hope someone can help.
I have a folder which is downloaded from my website. The folder contains a Main PDF report on a housing property, and another folder containing pictures and more PDF reports on similar houses in the area.
On my main PDF report I would like to have a link to open the other PDF folders.
How would I go about creating a link to open a PDF report saved in a file?
Looking at the picture below, where it says CS1.pdf, that is the name of the PDF and where the link will be. This is a screen shot of a portion of my main PDF.
I don't mind if the PDF reports are opened in a webpage, in fact I would prefer it. But, at the moment, I just need a simple link created that will open a PDF located in a folder.
An explanation of the app flow:
Here below I save the PDF that I want to link to later. It's saved to a temp location; the exact location is not important as it will be deleted after the file uploads.
The file I upload contains a few pictures, some PDFs and a data.XML file. When a person downloads the file, the data.XML file is used to create my main PDF, or report, in any format. I need to send a link through the XML file that will appear on the report making it able to link to the other PDF files that were uploaded with the data.xml file.
CS1[12].TagValue = ReportDS.Tables[9].Rows[0].ItemArray[0].ToString();
//Save PDF
//PDFName = System.Guid.NewGuid().ToString() + ".pdf";
string PDFName = "CS1" + ".pdf";
WebClient webClient = new WebClient();
webClient.DownloadFile(CS1[12].TagValue, "C://Users//Shaun//Documents//FormValue//" + PDFName);
CS1[12].TagValue = PDFName; //This is the value passed to the main PDF so this is where i should pass the link through.
The line CS1[12].TagValue = PDFName; is where I set the value to send though to the main PDF, and this is where my link should be sent through.
I need something like CS1[12].TagValue = "http://C://Users//Shaun//Downloads//CS1.pdf"; but with the file path of the downloaded location.

you are on a right way but you have some mistake like, when you giving location of pdf file from downloaded location, that must be a file type, its not from a server...
CS1[12].TagValue = "http://C://Users//Shaun//Downloads//CS1.pdf";
but it must like this
CS1[12].TagValue = "file://C://Users//Shaun//Downloads//CS1.pdf";
so that you have change one line in your code...
webClient.DownloadFile(CS1[12].TagValue, "file://C:/Users//Shaun//Documents//FormValue//" + PDFName);

Related

Open a PDF from a server in Edge or Chrome

I am working on a program created some years ago by a different programmer that, when a user clicks a link on a webpage, allows for a series of selections via dropdown boxes and such, which are used to populate a template PDF that is then saved as a new PDF. The program is then supposed to open that new PDF in that browser for the user to review and perhaps make further edits. This program is located on a virtual server along with many other web apps and related files. The template PDF and the new PDF file are located in the same place as the rest of the program.
From my testing, I can confirm that the link, the selections, and the populating of the template PDF work fine. A new PDF is saved with the proper selections, and I can find it in File Explorer on the server. I can even copy that new PDF from the server and paste it to my local device to then manually open for review.
The problem is that for some reason whenever the program itself tries to open the PDF, it comes up as a webpage of garbled text. I actually get the exact same output if I copy and paste the PDF to my local device and then change the extension to .html instead of .pdf (for what that is worth). I have tried multiple different means of opening the file.
The program uses iTextSharp to manipulate the PDF. I do not know much about iTextSharp so I do not know if that is part of the issue or not. I believe the code that is having the issue is as follows:
Server.Transfer("xp2Forms/completed_PDF" + indID + ".pdf");
File.Open(#"D:\Web Apps\IT Testing\xp2Forms\completed_PDF" + indID + ".pdf", FileMode.Open);
I have also tried replacing the last line with:
System.Diagnostics.Process.Start(#"D:\Web Apps\IT Testing\xp2Forms\completed_PDF" + indID + ".pdf");
The original code had:
OpenFile(#"D:\Web Apps\xp2Forms\Completed\completed_PDF" + indID + ".pdf");
Final piece of information. The PDF opens just fine in Internet Explorer. It just will not open in Chrome or Edge, at least not directly from the program. Again, I can open/paste and "Open With" Chrome or Edge no problem...
Thoughts?
I was able to address the issue by changing the "Server.Transer" line to "Response.Redirect" and now the PDF loads properly in both Microsoft Edge and Google Chrome.

Preselect Filename when printing to PDF

Can anyone recommend a tool that will allow me to set a registry key or a INI file, or something that will preselect the filename of a PDF when I print it?
I have written code to render some HTML in a web browser control, I simply want to export that HTML file to a PDF as easily as possible. Its been awhile since I have done this but I thought some of the free PDF printers had a registry key or an INI file I can insert a file name and that would make the SAVE dialog not appear and simply print the next file to that file name.
Win2PDF has a registry API to print to PDF while bypassing the save dialog. It also has an auto-name feature that will automatically name the PDF based on the document title, the current date, and the current time.

Downloading file from database where file is stored in binary format

I have got stuck in a problem while downloading documents from database.
Currently I'm working in ASP.net project and this is my first career project.
We have some documents which we store in database. The documents(.pdf,.doc,.png,.docx,xls,xlsx) are stored in binary format with their type specified.
I can download one document using Response.write. But now i have to concatenate some documents and then allow user to download on button click.
I have googled a lot. Developers have said that this is impossible. But still i feel that this can be done.
However if this is impossible i thought that i will save these individual documents first at some server location and then zip them and then allow user to download. But how would i be able to save the individual document in their original format at server location.
Please help me out. I'm in big problem.
It is not impossible to read more than one document from a database and zip them up before presenting the zip file to the response stream. You can do this all in process, there is no need to save the documents to the server.
This code uses Ionic.Zip to zip up several files and write them to a MemoryStream:
foreach (var file in files)
{
zipFile.AddEntry(file.FileName, file.ContentBytes); // these are the file bytes
}
var zipMs = new MemoryStream();
zipFile.Save(zipMs);
zipMs.Seek(0, SeekOrigin.Begin);
zipMs.Flush();
The file.FileName includes the extensions (.docx) of the documents and when downloading through the browser, everything is displayed and saved correctly.

How do I open a PDF file List in a new Window in ASP.NET?

How do I open a PDF file List in dialog box in a new Window in an ASP.NET application ?
I want list of pdf file which is stored in folder in my application and then select any of pdf and save in logged user's particular folder.
Since you want to display a list of pdf files stored in a folder on the server side you will need to render the list to a page in some format that makes sense. You may open that up as a dialog (perhaps using something like jquery ui) but it wouldn't be necessary.
Next to each file you could have a button that indicates the action you are after, say 'Copy'.
This would then send the id/name of the relevant file to the server and the server code could copy the file to some other location on the server that you refer to as the users folder.
However, if you want to download the file to the user's machine that is something else and you will find many answer here on SO about that.

how to show file on asp.net form

how to get file on asp.net form so that user can download it?
suppose i have created one excel file and i want to upload it on form so that user can download it, fill the details when they are offline.
You can use
Response.AddHeader("content-disposition", "attachment; filename=test.txt");
Response.WriteFile(#"test.txt");
Response.End();
Otherwise if it's a specific file you can use a normal Download Meand point it to the files location.
Use the fileupload component. I would store the file locally on the server and then display a list of the uploaded files.the list would be a list of hyperlinkswhich you can link directly to the uploaded files so when the user clicks on one, the file download begins automatically using the standard browser behavior.
Place the file in one of your directories under the application root folder and then you can simply place an anchor tag to let user download the file, like
abc

Categories