I have a feature in SharePoint that adds a webpart to the webpart gallery of every new site that is created. The offending lines of code are as follows:
string webPartPath = System.Web.Hosting.HostingEnvironment.MapPath("~/" +
CompanyConstants.CustomWebPart);
FileInfo f = new FileInfo(webPartPath);
FileStream s = f.Open(FileMode.Open, FileAccess.Read);
The string webPartPath evaluates to this:
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\template\layouts\*CENSORED*\*CENSORED*\WebPart\CustomWebpart.dwp
The error I receive is as follows:
The process cannot access the file 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\template\layouts*CENSORED**CENSORED*\WebPart\CustomWebpart.dwp' because it is being used by another process.
Does anyone know why this may be happening? Thanks so much in advance for your help.