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.