sharepoint-正则表达式在文档库取文件
[WebMethod] public byte[] GetAttachmentFileflowByName(string webPath, string listName, string regular) { try { using (SPSite site = new SPSite(webPath)) { SPWeb web = site.OpenWeb(); SPFolder folder= web.Folders[listName]; if (folder!=null) { SPFile file = GetFileFormFolder(folder, regular); if (file!=null) { return file.OpenBinary(); } } return new byte[] { }; } } catch (Exception) { return new byte[] { }; } } /// <summary> /// 在SPFolder中寻找指定regular文件 /// </summary> /// <param name="folder"></param> /// <param name="regular"></param> /// <returns>返回SPFile如无则返回null</returns> public SPFile GetFileFormFolder(SPFolder folder, string regular) { if (folder.Files.Count>0) { foreach (SPFile file in folder.Files) { if (System.Text.RegularExpressions.Regex.IsMatch(file.Name, regular)) { return file; } } } if (folder.SubFolders.Count>0) { foreach (SPFolder iFolder in folder.SubFolders) { if (GetFileFormFolder(iFolder, regular)!=null) { return GetFileFormFolder(iFolder, regular); } } } return null; }