ARTICLE

Define blocked file types in SharePoint 2010

Posted by Vijai Anand Articles | SharePoint 2010 February 09, 2011
We will be seeing about blocked file types in SharePoint 2010.
Reader Level:

In this article we will be seeing about blocked file types in SharePoint 2010. Each Web application maintains a list of blocked file types that is based on file name extensions which can be restricted from being uploaded or downloaded.

Using Central Administration:

  • Go to Central Administration => Security => General Security => Define blocked file types.

    Block1.gif
     
  • Select the web application from the drop down.
  • Type the file extension that has to be added in the blocked file types.
  • Click on Ok.

    Block2.gif

Using Visual Studio 2010:

  • Open Visual Studio 2010.
  • Go to File => New => Project.
  • Select Console Application from the installed templates.
  • Enter the Name and click Ok.
  • Add the following references.

    o Microsoft.SharePoint.dll
     
  • Add the following namespaces.

    o using Microsoft.SharePoint;
    o using System.Collections.ObjectModel;
     
  • Replace the code with the following.

     string webAppUrl = "http://serverName:10/";
     string addBlockFileType ="aspx";
     string removeBlockFileType ="asp";
     SPWebApplication webApp =SPWebApplication.Lookup(new Uri(webAppUrl));
     Collection<string> blockFileTypes = webApp.BlockedFileExtensions;
     foreach (string fileExtension in blockFileTypes)
     {
         // displaying all the file extensions that are blocked
         Console.WriteLine(fileExtension.ToString());
     }
     Console.ReadLine();

     // adding blocked file type
     blockFileTypes.Add(addBlockFileType);

     // removing blocked file type
     blockFileTypes.Remove(removeBlockFileType);

     webApp.Update();     

  • Build the solution.

  • Hit F5.

  • All the file extensions from the blocked file type will be displayed as shown in the following.

    Block3.gif
     

  • A new file extension "aspx" is added and the existing file extension "asp" is removed successfully.

Login to add your contents and source code to this article
comments
COMMENT USING
PREMIUM SPONSORS
Infragistics is experts in technology and design, and passionate about helping you build highly performant and stylish applications that solve problems, deliver inspiration, and maximize results.
HTML 5 + JQUERY CONTROLS
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.