IPAccessHelper.FormFile should dispose SPSite and SPWeb

Developer
Jul 22, 2008 at 8:21 PM
Hi,
I was browsing throught the code base to pickup new tricks. amazing stuff.

I have noticed a something in the IPAccessHelper.FormFile:

        public SPFile FormFile
        {
            get
            {
                if (_formFile == null)
                {
                    SPSite site = new SPSite(WorkflowProperties.SiteId);

                    SPWeb web = site.AllWebs[WorkflowProperties.WebId];

                    _formFile = web.GetFile(WorkflowProperties.ItemUrl);
                }

                return _formFile;
            }
        }

        public SPFile FormFile
        {
            get
            {
                if (_formFile == null)
                {
                    using( SPSite site = new SPSite(WorkflowProperties.SiteId) )
                    {
                        using(SPWeb web = site.AllWebs[WorkflowProperties.WebId] );
                        {
                            _formFile = web.GetFile(WorkflowProperties.ItemUrl);
                        }
                   }
                }

                return _formFile;
            }
        }

This change will dispose the two objects properly.