0

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:

  1. A namespace cannot directly contain members such as fields or methods

  2. 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" %>
Sam Cromer
  • 687
  • 3
  • 12
  • 31
  • I can copy your code exactly (commenting out the two `APP_Code` lines) and it works fine. Also, if you look at my example in my [previous post](http://stackoverflow.com/questions/19123961/filehandler-in-asp-net/19124733#19124733), you don't have to mess around with query strings and switch statements... why not just link directly to the PDF? This route would be a pain every time you add a new file. – MikeSmithDev Oct 02 '13 at 14:40
  • Thanks @MikeSmithDev , I will be changing this to remove the switch statement and just pull the file info from the database once this is ok'd during testing, it's sort of a "proof of concept" solution I just wanted to be certain it worked before I cleaned it up. It wasnt building because the ashx file was set to compile for some reason. – Sam Cromer Oct 02 '13 at 19:45

1 Answers1

0

I figured it out... The ashx file itself was set to compile, changed it to content and compile only the cs file and it builds..

Sam Cromer
  • 687
  • 3
  • 12
  • 31