C# open file from physical path - c#

sorry for asking a silly question it seems to be,
I am new to programming and trying to write a asp .net web application.
One part of the application had generated and saved some document
(like pdf, excel, words, gif, jpg, etc.) to a physical path in server side,
User can choose to download the file by clicking a button
is there something like "window.open(url)" that can raise a file download dialog box with known document type in javascript / c#?
Thanks a lot!!

Related

Sending HTML file with Images through email IOS

This is more of a general question about whether or not its actually possible to achieve what I want.
The basis is that my app allows the user to fill out various tables of data for a preventative maintenance check sheet. They can also attach images to this sheet which saves to the temporary storage on the IOS app. Once its complete they then press a button which generates a HTML document through a StreamWriter. Through this StreamWriter I have created, the images are also appended through URL references to the images in the temporary folder.
The HTML file (Generated Form) is then presented to the user using a WebView. Once the user has checked all the information, they then press a button which presents a MailViewController.
The HTML file (Generated Form) is then automatically attached and once the email has been entered you press send and everything works as it should.
The problem I am now having is that im not sure if its possible to keep the images in the html document. Once you open the HTML file on the receiving device, the images no longer loads because they no longer exist according to the HTML file.
So basically is it possible to keep the images in the HTML file once opened on the receiving device.
Sorry for the long description but its needed so you get an understanding of what I am actually doing. All the code I have written works as it should but just wanted to know if this is possible or not.
Thanks
Jamie
Use base 64 encoded strings for the images and it should work. Since the images would be passed along with the html

Print doc files in asp.net mvc project

I am working on an asp.net mvc project. How can I open doc.file to print it from page? The only thing I can do now is downloading, however, I'd like to open it as print friendly file in sort of window.print()
Normally you just supply correct content type. Then user can view the file inside the browser and print it.
However, if the browser doesn't have appropriate plugin, then user can only download the file.
public ActionResult Download()
{
return File("~/MyDocument.doc", "application/vnd.ms-word", "MyDocument.doc");
}
.doc files are designed to be opened with MS Word (and at one point there was a Word Viewer presumably designed for this sort of thing). There are also other apps (e.g. OpenOffice / LibreOffice) which will allow you to read & write MS Word documents with varying degrees of success.
So one option -- as #Win points out -- is to require that users have some compatible application installed. You frequently see this with PDF files, the site will typically contain a link to download Adobe (Acrobat) Reader. The external app will be used to display the file; if the app can run as a plugin the content will be displayed "inside" the browser.
If the app is primarily intended for users internal to your business, and they all have Office installed, then that's a perfectly acceptable solution.
If you want the content to be available people who don't have Office (and/or don't run Windows) it gets much more difficult. You'd need to either:
write an MVC view that will parse/render .doc files (not for the faint of heart)
convert the content to some other format (PDF or HTML) that's more easily "consumed".

Download contents of html text area tag as word or pdf file in c#

I am working on a ASP .NET project where the requirement is to download a text area content as a file like .doc, .pdf and .txt.
I know we can download the plain text of text area as .txt using java script but the thing I want to know is,
How can I achieve the same for .doc and .pdf
is there any java script/jquery way to achieve this if not then what is the right way to do this in native C#.
examples or links would be great.
PDF and Word Documents are complex file types. If you want to generate these files client side, you'll need a javascript library that can generate files in these formats. I don't think these exist (as this is an uncommon request), but you can google it.
If I would be faced with a problem like this, I would post the value of the textbox back to the server and generate the files on the server. This SO post discusses how to create a pdf file in C#: How to generate a PDF?
Once you have created the file server side, you can then send it back to the client.

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.

Creating RTF and printing as PDF

I'm trying to do the following(in this order):
Create a Rich Text Format file
Add company image to the top of page and write the data to the RTF
Print the RTF file as PDF through CutePDF or other printer that are
able to convert my RTF to a PDF and thereby save locally on the users PC - The pdf should be saved at a location without prompting the user
After this is done, the RTF file should be deleted and return a message, that confirms the action is successfully done.
Other stuff:
The website where these actions take place, are not meant to host the outcome(the PDFs) but these are supposed to be saved on the users PC. (is this possible without prompting the user to save it? i imagine the website would write directly to the users PC instead of doing the work on the website and save it and then transfer the file to the PC)
OBS: i do not wish to use any 3th party program/DLL other then the converter like cutePDF :)
My question is quite simple i hope :)
Will this work?
No. You can send the PDF back to the user but the user will either be prompted to download the file or it will open automatically (depending on the user's configuration and the response headers you're sending). Without using some sort of plugin you can't save any files directly to the user's computer.
If it was possible to write a file directly to the user's the world as we know it would have ceased to exist. Cities would lie in ruin as idle youtube commentators roamed the streets in violent gangs yelling "FIRST" and engaging in brutal and pointless gang wars. A generation of youth superbly trained by video games would manage to destroy civilization in a matter of days. Fortunately civilization would eventually be rebuilt by Minecraft players but it would take time.
If that functionality is really vital I would suggest looking at a plugin.

Categories