2

I want to limit the file upload size for a specific document library in SharePoint 2010. I do know that the upload size is for the entire web-application rather than a specific site/sub-site/library.

My scenario is: I have a document library where users would be uploading media files (video, audio...). I want to limit the upload size to 10 MB instead of 50 MB across the web-application.

1

You cannot control the File Size limit at Document library level OOTB. What you need, you have to write your own code may be some event receiver.

Check this code from this post

{
     long validFileSize;
     long currentFileSize;
     if (properties.ListItem == null)
     {
             using (SPWeb web = properties.OpenWeb())
             {
                    if (!web.CurrentUser.IsSiteAdmin)
                   {
                          if (properties.ListTitle.ToLower() == "images")
                         {
                                 if (ConfigurationManager.AppSettings["FileSize"] != null)
                                 {
                                        validFileSize = long.Parse(ConfigurationManager.AppSettings["FileSize"].ToString());
                                 }
                                 else
                                {
                                       validFileSize = 1000000;//1MB
                                }
                               currentFileSize = long.Parse(properties.AfterProperties["vti_filesize"].ToString());
                               if (currentFileSize > validFileSize)
                              {
                                      return false;
                              }
                        }
                 }
          }
    }
    else if (properties.ListItem.ParentList.Title.ToLower() == "images")
    {
          if (!properties.ListItem.Web.CurrentUser.IsSiteAdmin) 
         {
                 if (ConfigurationManager.AppSettings["FileSize"] != null)
                 {
                        validFileSize = long.Parse(ConfigurationManager.AppSettings["FileSize"].ToString());
                 }
                 else
                 {
                        validFileSize = 1000000;//1MB
                 }
                 currentFileSize = properties.ListItem.File.TotalLength;
                 if (currentFileSize > validFileSize)
                {
                      return false;
                }
         }
    }
    return true;
} 
2

As you said, you can modify the size limit in the web application and IIS. Out of the box, you can't adjust this for a list/library.

A possible solution would be to create your own form for "new item" that would check for the file size before uploading it to the document library.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.