How to use VS to insert a ashx file in Sharepont 2013

Source: Internet
Author: User

http://www.lifeonplanetgroove.com/adding-and-deploying-generic-handlers-ashx-to-a-sharepoint-2010-visual-studio-project/

Adding and deploying Generic handlers (. ASHX) to A SharePoint in Visual Studio projectasp.net, SharePoint, Technology by ADAM TOTH on October

Generic handlers (. ashx files) deployed to the _layouts directory is not directly supported by Visual Studio Sharepo int projects like custom. aspx application pages is. This post would cover how to add them to your Visual Studio project and deploy them properly to the ISAPI folder.

Overview

Visual Studio Item Templates for Generic handlers (. ashx files) is not directly supported by Visual Studio Harepoint projects.

IMPORTANT UPDATE 4/30/2013! I contributed an ASHX ItemTemplate to the Cksdev team that's now included in the the and the versions of the extensions (see http://www.lifeonplanetgroove.com/2013/04/30/ashx-generic-handlers-and-sharepoint-now-in-cksdev/). The manual approach below is still a option, but the cksdev approach makes it much more seamless. Special thanks to Wes Hackett for merging the contribution.

If you try to Add New Item ... and select the Web or SharePoint categories in a VS. SharePoint project, you won ' T find Generic Handler anywhere.

You'll find ASP. Handler, but this would require you to create entries in Web. config to make your Handler work. In order to add a new. ASHX generic handler and get it to deploy properly, you can use the following steps:

  • Right-click the project, and select Add New Item ...
  • Choose the application Page template.
  • In the Name box, enter a name of your file, with a . ashx extension.
  • Open the . ashx file, delete the contents and replace with the following, changing your class= attribute W ith your desired namespace and class name:
    <%@ Assembly name= "$SharePoint. project.assemblyfullname$"%><%@ Assembly name= "Microsoft.SharePoint, version=14.0.0.0, Culture=neutral, publickeytoken=71e9bce111e9429c "%><%@ WebHandler Language=" C # "class=" Mynamespace.mygenerichandler "%>

    NOTE

    If you want to reference other SharePoint assemblies in your code-behind, you'll need to add a @ Assembly directive for Each DLL.

  • Open theAshx.csFile.
      • Add a  using  statement for  system.web .
      • you probably don ' t need the  using  statement for  Microsoft.SharePoint.WebControls , so remove it.
      • change your namespace if necessary.
      • change the class to inherit from  IHttpHandler .
      • Implement the  IHttpHandler  interface. Your code should now look something like This:
        using microsoft.sharepoint;using system.web;        namespace mynamespace{public partial class Mygenerichandler:ihttphandler {#region IHttpHandler members        public bool IsReusable {get {throw new NotImplementedException ();}        } public void ProcessRequest (HttpContext context) {throw new NotImplementedException (); } #endregion}} 
  • In the solution Explorer, delete the ashx.designer.cs file, it's not needed.
  • In the solution Explorer, click the . ashx file, and in the Properties pane, set the Build A Ction to Content.
  • In the solution Explorer, click the . Ashx.cs file, and in the Properties pane, set the Bui LD Action to Compile.
  • Make sure to enable Token replacement for . ASHX extensions. This would replace $SharePoint.Project.AssemblyFullName$ the token with the full strong name of your assembly, enabling-to-reference other classes in Yo Ur compiled assembly from the Ashx Code-behind. You can read more about tokens replacement here. To enable the your project, Unload your project, Edit the. csproj file and add the following text to a PropertyGroup, and Reload your project:
    <propertygroup><tokenreplacementfileextensions>ashx</tokenreplacementfileextensions></ Propertygroup>

How to use VS to insert a ashx file in Sharepont 2013

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.