I come from a ColdFusion background, and CF has the ability (via something
called CFCONTENT) which allows you to serve up a file which resides outside
your web root directory.
How do I accomplish a similar thing using ASP.net 2 (C#)?
Basically, my web app is creating a PDF document and storing it in C:\PDFS
In my app, I want to have a LinkButton which will serve up the PDF (located
in C:\PDFS) to the user.
I DO NOT want to have the PDFs in the web app's directory structure because
you have to log into the app to use it. And I don't want just anyone to be
able to link to the PDF.
Thanks in advance for any advice,
BrianCold Fusion, ha good times there.
In C# you would use something like
DirectoryInfo dir = new DirectoryInfo("c:\\pdfFiles);
FileInfo[] pdfFiles= dir.GetFiles("*.pdf");
foreach(FileInfo f in pdfFiles)
{
Response.Write("<br><a href="http://links.10026.com/?link= + f.Name + ">" + f.Name + "</a>");
}
"Brian Simmons" <centraso@.newsgroup.nospam> wrote in message
news:%23c5n%23jB4HHA.4672@.TK2MSFTNGP05.phx.gbl...
>I come from a ColdFusion background, and CF has the ability (via something
>called CFCONTENT) which allows you to serve up a file which resides outside
>your web root directory.
> How do I accomplish a similar thing using ASP.net 2 (C#)?
> Basically, my web app is creating a PDF document and storing it in C:\PDFS
> In my app, I want to have a LinkButton which will serve up the PDF
> (located in C:\PDFS) to the user.
> I DO NOT want to have the PDFs in the web app's directory structure
> because you have to log into the app to use it. And I don't want just
> anyone to be able to link to the PDF.
> Thanks in advance for any advice,
> Brian
>
http://support.microsoft.com/kb/306654
Rather than using MapPath, just supply the actual directory.
"Brian Simmons" <centraso@.newsgroup.nospam> wrote in message
news:%23c5n%23jB4HHA.4672@.TK2MSFTNGP05.phx.gbl...
>I come from a ColdFusion background, and CF has the ability (via something
>called CFCONTENT) which allows you to serve up a file which resides outside
>your web root directory.
> How do I accomplish a similar thing using ASP.net 2 (C#)?
> Basically, my web app is creating a PDF document and storing it in C:\PDFS
> In my app, I want to have a LinkButton which will serve up the PDF
> (located in C:\PDFS) to the user.
> I DO NOT want to have the PDFs in the web app's directory structure
> because you have to log into the app to use it. And I don't want just
> anyone to be able to link to the PDF.
> Thanks in advance for any advice,
> Brian
>
Also ignore the "Add the PDF File to the Project" section :) As you want
the file outside your web space
"Aidy" <aidy@.xxnoemailxx.com> wrote in message
news:iKGdnaUWU_Dw7lnbnZ2dnUVZ8sqjnZ2d@.bt
.com...
> http://support.microsoft.com/kb/306654
> Rather than using MapPath, just supply the actual directory.
> "Brian Simmons" <centraso@.newsgroup.nospam> wrote in message
> news:%23c5n%23jB4HHA.4672@.TK2MSFTNGP05.phx.gbl...
>
Hi Brian,
This is a piece of cake in ASP.NET since you can utlize the powerful
functionality of .net framework components. As other members have
suggested, you can use the System.IO classes to get binary data from the
external file system (even on remote share folder) and write it out to
page's response stream. e.g.
======================
protected void Page_Load(object sender, EventArgs e)
{
byte[] bytes = null;
string path = @."d:\filestore\pdf_files\test.pdf";
bytes = File.ReadAllBytes(path);
Response.ClearHeaders();
Response.ClearContent();
Response.ContentType= "application\pdf";
Response.AddHeader("Content-disposition", "attachment;
filename=test.pdf");
Response.Write(bytes);
Response.End();
}
===========
Here is a web article also mentioned this:
#Secure File Download Page
http://www.codeproject.com/aspnet/S...ileDownload.asp
In addition, you can even get the file content from other storage such as
database, webservice .... It's quite flexible when you use the .net
frameowork classes to deal with the things:)
Hope this also helps.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
Thursday, March 22, 2012
Serve up file from outside web application directory
Labels:
ability,
allows,
application,
asp,
background,
cfcontent,
coldfusion,
directory,
file,
net,
outside,
resides,
serve,
somethingcalled,
via,
web
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment