|
|
|
start date: Thu, 16 Aug 2007 11:20:27 -0400,
posted on: microsoft.public.dotnet.framework.aspnet
back
| Thread Index |
|
1
Brian Simmons am
|
|
2
Mike
|
|
3
Aidy
|
|
4
Aidy
|
|
5
(Steven Cheng[MSFT])
|
|
6
(Steven Cheng[MSFT])
|
Serve up file from outside web application directory
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
Date:Thu, 16 Aug 2007 11:20:27 -0400
Author:
|
Re: Serve up file from outside web application directory
Cold 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=" + 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
>
Date:Thu, 16 Aug 2007 11:30:06 -0400
Author:
|
Re: Serve up file from outside web application directory
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
>
Date:Thu, 16 Aug 2007 16:55:23 +0100
Author:
|
Re: Serve up file from outside web application directory
Also ignore the "Add the PDF File to the Project" section :) As you want
the file outside your web space
"Aidy" 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...
>>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
>>
>
>
Date:Thu, 16 Aug 2007 16:56:22 +0100
Author:
|
Re: Serve up file from outside web application directory
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/SecureFileDownload.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.
Date:Fri, 17 Aug 2007 02:42:19 GMT
Author:
|
Re: Serve up file from outside web application directory
Hi Brain,
Any further questions on this? If so, please feel free to post here.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
Date:Tue, 21 Aug 2007 08:45:28 GMT
Author:
|
|
|