Share via


How To: Add Blocked File Types

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

This programming task shows how to create a simple console application to modify administrative property settings in a SharePoint Web application. The example uses the SPWebApplication.BlockedFileExtensions property to modify the list of blocked file types for a specified Web application.

Note

Changes that you make to administrative settings will be disseminated asynchronously across the server farm and may require a few minutes to take effect.

To create a console application that adds blocked file types

  1. On the File menu in Visual Studio 2005, point to New and then click Project.

  2. In the New Project dialog box, select a language, and then select Visual C# in the Project Types box.

  3. In the Templates box, select Console Application.

  4. In the Location box, type the path to where to create the application, and then click OK.

  5. In Solution Explorer, right-click the References node, and then click Add Reference on the shortcut menu.

  6. On the .NET tab of the Add Reference dialog box, select Windows SharePoint Services in the list of components, and then click OK.

  7. In the .vb or .cs file, add directives to import the System.Collections.ObjectModel and Microsoft.SharePoint.Administration namespaces, as follows.

    Imports System.Collections.ObjectModel
    Imports Microsoft.SharePoint.Administration
    
    using System.Collections.ObjectModel;
    using Microsoft.SharePoint.Administration;
    
  8. Add the following code to the Main method in the .vb or .cs file.

    Dim webAppUrl As String = Console.ReadLine()
    Dim myBlockFileType As String = Console.ReadLine()
    
    Dim myUri As New Uri(webAppUrl)
    Dim myWebApp As SPWebApplication = SPWebApplication.Lookup(myUri)
    Dim blockFileTypes As Collection (Of String ) = myWebApp.BlockedFileExtensions
    blockFileTypes.Add(myBlockFileType)
    myWebApp.Update()
    
    string webAppUrl = Console.ReadLine();
    string myBlockFileType = Console.ReadLine();
    
    Uri myUri = new Uri(webAppUrl);
    SPWebApplication myWebApp = SPWebApplication.Lookup(myUri);
    Collection<string> blockFileTypes = myWebApp.BlockedFileExtensions;
    blockFileTypes.Add(myBlockFileType);
    myWebApp.Update();
    

    To remove a file extension, use the Remove method instead, and update the Web application as in the example.

  9. On the Debug menu, click Start, or press F5 to run the code.

See Also

Reference

Microsoft.SharePoint.Administration

Other Resources

Programming in Windows SharePoint Services