I have a generic handler that serves PDF's depending on a querystring. I haven't used Handlers before but when I build I get 2 strange errors that I can't find a solution for: The errors are:
A namespace cannot directly contain members such as fields or methods
Keyword, identifier, or string expected after verbatim specifier: @
here is the code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Center
{
/// <summary>
/// This tracks user opens serves the proper PDF by querystring value f
/// </summary>
public class GetFile : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
//Get file reference
if (context.Request.QueryString["f"] != null)
{
string file;
string fullFilePath;
string fileName;
file = context.Request.QueryString["f"];
switch (file)
{
case "Access":
App_Code.bi.LogFileDownload("Access Fact Sheet", context.Session["UserID"].ToString());
fullFilePath = "files/Access2013.pdf#zoom=100";
fileName = "Access2013.pdf";
context.Response.Clear();
context.Response.ContentType = "application/pdf";
context.Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
context.Response.TransmitFile(fullFilePath);
context.Response.End();
break;
case "MobileApp":
fullFilePath = "files/mobile_app.pdf#zoom=100";
fileName = "mobile_app.pdf";
context.Response.Clear();
context.Response.ContentType = "application/pdf";
context.Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
context.Response.TransmitFile(fullFilePath);
context.Response.End();
break;
case "BillingFact":
fullFilePath = "files/billing_factsheet.pdf#zoom=100";
fileName = "billing_factsheet.pdf";
context.Response.Clear();
context.Response.ContentType = "application/pdf";
context.Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
context.Response.TransmitFile(fullFilePath);
context.Response.End();
break;
case "HistoricalFact":
fullFilePath = "files/Implementation.pdf#zoom=100";
fileName = "Implementation.pdf";
context.Response.Clear();
context.Response.ContentType = "application/pdf";
context.Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
context.Response.TransmitFile(fullFilePath);
context.Response.End();
break;
case "ImplementationKit":
App_Code.bi.LogFileDownload("Implementation Kit", context.Session["UserID"].ToString());
fullFilePath = "files/Implementation_kit.pdf#zoom=100";
fileName = "Implementation.pdf";
context.Response.Clear();
context.Response.ContentType = "application/pdf";
context.Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
context.Response.TransmitFile(fullFilePath);
context.Response.End();
break;
}
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
ASHX file
---------------
<%@ WebHandler Language="C#" CodeBehind="GetFile.ashx.cs" Class="Center.GetFile" %>