Article ID: 306575 - Last Review: June 29, 2004 - Revision: 3.3 How To Dynamically Include Files in ASP.NETThis article was previously published under Q306575 On This PageSUMMARY This article demonstrates how to dynamically include HTML
and client-side scripts in .aspx pages. Because ASP.NET applications are compiled and run before they are sent to the client, you cannot use a variable in place of a file name in a server-side include file (such as <!-- #include PathType = FileName -->"). However, you can use the Response or StreamReader object to write the include file to the HTTP content stream. This article demonstrates how to create an .aspx page that reads a file with static HTML and/or client-side script code and writes the file's content to the browser. MORE INFORMATION In ASP.NET, the Response object provides a new method named WriteFile. You can use the WriteFile method to write the specified file directly to an HTTP content
output stream. If you only want to write the content of a file to the browser, you can accomplish this in just one statement. If you want to manipulate the file before you send it to the browser, refer to the References section for information about basic file input/output in .NET. In ASP.NET, you can either write inline code or write code in the code-behind module. This article presents an inline code sample that opens a file and writes the file's content to the browser. Steps to Create the Sample
Troubleshooting
REFERENCESFor additional information, click the article numbers
below to view the articles in the Microsoft Knowledge Base: 304427
(http://support.microsoft.com/kb/304427/EN-US/
)
How To Do Basic File I/O in Visual Basic .NET
304430
(http://support.microsoft.com/kb/304430/EN-US/
)
How To Do Basic File I/O in Visual C# .NET
| Article Translations
|

Back to the top
