2 ways to change the Work Item’s maximum attachment size in TFS 2010 / 2012

Posted by Leo Vildosola - July 25, 2012

header-picture

If you work with TFS 2010 or TFS 2012 work items, you know you can attach files. Sometimes you need to attach large files. If these are too big TFS will tell you about it.

SNAGHTML6bb62f9

As suggested, you can put the file in Source Control and then link to it. However, if you really need to attach the file, you can increase the size limit for the attachments.

Below you will find 2 methods you can use to accomplish this.

Method #1 – Web Service

  1. Navigate to http://localhost:8080/tfs/<CollectionName>/WorkItemTracking/v1.0/ ConfigurationSettingsService.asmx?op=SetMaxAttachmentSize
  2. Enter the new value (in bytes, up to 2 GB) in the maxSize field
  3. Click Invoke

Method #2 – C#

Programmatically, update the value directly in the TFS Registry.

<span style="color: #008000">/// &lt;summary&gt;</span>

<span style="color: #008000">/// Sets the maximum attachment size for the given server.</span>

<span style="color: #008000">/// &lt;/summary&gt;</span>

<span style="color: #008000">/// &lt;param name="tfsUrl"&gt;The TFS URL.&lt;/param&gt;</span>

<span style="color: #008000">/// &lt;param name="newAttachmentSize"&gt;The new maximum attachment size.&lt;/param&gt;</span>

<span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> SetMaximumAttachmentSize(<span style="color: #0000ff">string</span> tfsUrl, <span style="color: #0000ff">long</span> newAttachmentSize)

{

    var configServer = TfsConfigurationServerFactory.GetConfigurationServer(<span style="color: #0000ff">new</span> Uri(tfsUrl));

    var rw = configServer.GetService&lt;ITeamFoundationRegistry&gt;();

    var rc = rw.ReadEntries(<span style="color: #006080">@"/Service/WorkItemTracking/Settings/MaxAttachmentSize"</span>);

    <span style="color: #0000ff">if</span> (rc.Count &gt; 0)

    {

        var re = rc.First();

        re.Value = newAttachmentSize.ToString(CultureInfo.InvariantCulture);

        rw.WriteEntries(<span style="color: #0000ff">new</span> List&lt;RegistryEntry&gt; { re });   

    }

}

Topics: Blog


Recent Posts

What's New in Azure DevOps?

read more

InCycle Named 2020 Microsoft US Partner Award Winner

read more

What Is Container Image Management?

read more