How do i create a file from page request
Lets say if i'm on Page A and need to have the file from Page B.
Page B returns a .XLS file format on the fly with response.output.
How do i get this as an File i need to attach this to an attachment i dont like
copy the whole code from Page B since i dont think thats realy needed.
ive tried a WebGetter but that does'nt realy works that well.
if you have any tips or snippets that would be awesome.
I code in VB.net.
Regards,
Stefan
Related
I tried to make my title as direct as humanly possible.
I wrote some code, saved it in a file. I want the name of that file, and the disk path to it, at the moment it runs. This is for a website, and I have access to HttpContext.
I wrote some code in a Razor file. I put that file on my IIS website, and it got executed by some convoluted hierarchy steps with partials and the like. I want to write some code that spits out the path to that file.
I don't want to hard-code the filename and its current path in my code. I want to copy the magic piece of code I'm asking for here onto lots of other Razor pages, so each time I can spit out a comment in some script or style tag somewhere so that other developers can track down my mistakes amazing work.
I don't want to know how the end-user's browser got to my file. I'd use Server.MapPath or Request.ServerVariables["SCRIPT_NAME"] if I wanted that.
I don't want to know merely what directory my website app is running in. I'd use HttpContext.Current.Request.PhysicalPath for that.
Does anybody know how to do this?
I am currently trying to implement an atom feed for my Umbraco website (The question is not Umbraco specific, please don't tag with 'Umbraco'). For testing purposes I've copied an atom feed that I found on the web (please don't tell anybody, it's probably illegal) and pasted the content inside a page template. The resulting output is an .aspx - page, which contains nothing but the pasted code:
Not working on aspx - page
As you can see, it is not working, the feed is shows as text, no subscribe options and the like. Accessing the feed with a C# atom API yields an exception, saying the feed type cannot be determined.
Now I've taken the exact same content and pasted it inside another file, this time with the ending .asp, which you can see here:
Working on asp - page
It works. It also works when I rename the file ending to .htm, .html or .xml.
My questions (I've got two) (thanks in advance):
a) Are atom feeds generally not working when the file ending is .aspx?
b) How can I provide an atom feed on an .aspx site, when I can't change the file ending?
Ok, found it thanks to this question:
SO Thread
There were blank lines on top of the document in the .aspx file...
We have files on server of several types (.pdf, .docx, .jpeg). The scenario is a user press a button (a link) and the print dialog opens which will print the content of a file chosen.
Can you please advise solutions to do it?
I think it's gonna be a link to another page where we fill in response with a file content and JavaScript window.print();
The option you've considered (opening the file in a new page) is a good one. You could also try doing the same thing but in an iframe. That would maybe be a better user experience if you want to avoid a new page/tab opening up.
Hi
I'm attempting to use the ASPFPDF class to output an image on a pdf using the very simple code below:
<!--#include file="fpdf.asp"-->
<%
Dim pages
Dim pdf
Set pdf=CreateJsObject("FPDF")
pdf.CreatePDF "P", "mm", "A4"
pdf.SetPath "fpdf/"
pdf.Open()
pdf.AddPage("P")
pdf.Image "invoiceheader.jpg"
pdf.Output ()
%>
When run, this script should open the pdf but with Adobe Reader I get a "File does not begin with %pdf" message. I've tried using other readers with similar results.
If I remove the image line and output some text (e.g. pdf.Cell 40,5,"Date",0,1,"R"), everything works perfectly.
Anyone got any ideas before I go mad!
Thank you.
Try this one
pdf.Image "IMAGES/invoiceheader.jpg", 140, 22, 50, 40
Here 140 is the x position, 22 is the y-position 50 is the width and 40 is the height.
I don't know AspFPdf, but don't you need to specify a folder where the image is to be found ?
Did you try ?
pdf.Image "fpdf/invoiceheader.jpg"
As I said, I don't know the component, just my thoughts (although you have propably tried this yourself).
[EDIT] Look at the website of Asp Fpdf and saw the following in the documentation:
file
Path or URL of the image.
Asp fPdf : Image parameter
Anyway: thanks for pointing me in the direction of this component (even though this was not your intention). I can use this too ;-)
Just thought I'd update people as I've spent ages and have finally got this working. What you don't see due to random error messages is that the FPDF application creates a temporary PDF as it's building it. By default, it will create it in the same folder as your asp page that runs it.
e.g. My page was in my web root \createpdf.asp
I worked out that it was trying to create a file called D10456.tmp (name changes each time) in my web root but it couldn't due to security.
I added an output file name and changed the security in another folder to allow write access and it worked first time.
Code for output file:
pdf.Output server.mappath("pdfs\list.pdf"),"F"
The PDFS folder must have write access to work.
Hope that helps people.
The answer by Paul is also correct for the format of adding an image in ASP.
Also, I had to change the images.asp file which is located in the includes directory.
I had to change the line:
this.Buffer.LoadFromFile(Server.MapPath("\\") + ("\\") + ("Images") + ("\\") + pFileName);
to
this.Buffer.LoadFromFile(Server.MapPath(pFileName));
because it was looking in the wrong folder for my images.
The answer to the above question is that the FPDF seems to need to be on a fully qualified domain - I was running on a machine with using a custom hosts file to point the URL at the development server. As soon as I moved the code to the live server, everything worked!
I don't fully understand why, but this might help someone else...
I found that the only way I could add images was as follows:-
pdf.Image "./byimage.jpg",x,y,width
This is how i manage to display my image in ASP classic page:
pdf.Image "fpdf/header.jpg", 10, 10,80,20, "jpg"
if not mistakes, this is how to define the variables (correct me if i'm wrong):
pdf.image "folder/image.type", x-coordinate, y-coordinate, img width, img height, "image type"
hope it helps. because i've spent many days just to find how to display the image in my asp classic page..
We're building a CMS. The site will be built and managed by the users in aspx pages, but we would like to create a static site of HTML's.
The way we're doing it now is with code I found here that overloads the Render method in the Aspx Page and writes the HTML string to a file. This works fine for a single page, but the thing with our CMS is that we want to automatically create a few HTML pages for a site right from the start, even before the creator has edited anything in the system.
Does anyone know of any way to do this?
I seem to have found the solution for my problemby using the Server.Ecxcute method.
I found an article that demonstared the use of it:
TextWriter textWriter = new StringWriter();
Server.Execute("myOtherPage.aspx", textWriter);
Then I do a few maniulatons on the textWriter, and insert it into an html file. Et voila! It works!
Calling the Render method is still pretty simple. Just create an instance of your page, create a stub WebContext along with the WebRequest object, and call the Render method of the page. You are then free to do whatever you want with the results.
Alternatively, write a little curl or wget script to download and store whichever pages you want to make static.
You could use wget (a command line tool) to recursively query each page and save them to html files. It would update all necessary links in the resulting html to reference .html files instead of .aspx. This way, you can code all your site as if you were using server-generated pages (easier to test), and then convert it to static pages.
If you need static HTML for performance reasons only, my preference would be to use ASP.Net output caching.
I recommend you do this a very simple way and don't do it in code. It will allow your CMS code to do what the CMS code should do and will keep it as simple as possible.
Use a product such as HTTrack. It calls itself a "website copier". It crawls a site and creates html output. It is fast and free. You can just have it run at whatever frequency you think is best.
It decouples your HTML output needs from your CMS design and implementation. It reduces complexity and gives you some flexibility in how you output the HTML without introducing failure points in your CMS code.
#ckarras: I would rather not use an external tool, because I want the HTML pages to be created programmatically and not manually.
#jttraino: I don't have a time interval in which the site needs to be outputted- the uotput has to occur when a user creates a new site.
#Frank Krueger: I don't really understand how to create an instance of my page using WebContext and WebRequest.
I searched for "wget" in searchdotnet, and got to a post about a .net class called WebClient. It seems to do what I want if I use the DownloadString() method - gets a string from a specific url. The problem is that because our CMS needs to be logged in to, when the method tries to reach the page it's thrown to the login page, and therefore returns the login.aspx HTML...
Any thoughts as to how I can continue from here?