- Microsoft .NET Framework
- Microsoft Windows 2000 or Windows XP
- Microsoft Internet Information Server (IIS)
- Open Microsoft Visual Studio .NET
- From the File menu, point to New, and then click Project.
- Under Project Types, click Visual C# Projects. Under Templates, click ASP.NET Web Application.
- In the Name text box, type BinaryDemo. In the Location text box, type the server name. If you are using the local server, leave the location as http://localhost.
- In Solution Explorer, right-click the project node, click Add, and then click Add Existing Item.
- Browse to the location of a .pdf file on your system.
- Click to highlight the file, and then click Open.
- In Visual Studio .NET Solution Explorer, right-click the file, and then click Rename. Rename the .pdf file so that it matches the file name Acrobat.pdf that is used in the code that follows.
- Add a new .aspx page named BinaryData.aspx to the current project as follows:
- In Solution Explorer, right-click the project node, click Add, and then click Add Web Form.
- Name the page BinaryData.aspx, and then click Open.
NOTE: Make sure that your page is added to the project at the same level as the .pdf file that you added in the previous section. This is very important because the code uses the relative path to initially reference the .pdf file.
- In the editor, right-click BinaryData.aspx, and then click View Code.
- Highlight the following code, right-click the code, and then click Copy. In the Page_Load event in the code-behind page, click Paste on the Edit menu to paste the code:
private void Page_Load(object sender, System.EventArgs e)
//Set the appropriate ContentType.
Response.ContentType = "Application/pdf";
//Get the physical path to the file.
string FilePath = MapPath("acrobat.pdf");
//Write the file directly to the HTTP content output stream.
- On the File menu, click Save All.
- On the Build menu, click Build.
- To run the code, right-click BinaryData.aspx in Solution Explorer, and then click View In Browser. If you are prompted, click Open to open and render the file in the browser.
- "Application/msword" (for Microsoft Word files)
- "Application/x-msexcel" (for Microsoft Excel files)
The third-party products that are discussed in this article are manufactured by companies that are independent of Microsoft. Microsoft makes no warranty, implied or otherwise, regarding the performance or reliability of these products.
ID articol: 306654 - Ultima examinare: 12 iun. 2012 - Revizie: 1