0
我正在寻找一种将txt文件类型添加到C#中有问题的Windows搜索的内容索引的方法。 注意我不想通过使用file.setattribute添加单个txt文件。我想检查txt文件类型的索引属性和文件内容是否有问题。如何将txt文件以编程方式添加到Windows搜索索引
我正在寻找一种将txt文件类型添加到C#中有问题的Windows搜索的内容索引的方法。 注意我不想通过使用file.setattribute添加单个txt文件。我想检查txt文件类型的索引属性和文件内容是否有问题。如何将txt文件以编程方式添加到Windows搜索索引
我找到了一种方法来做到这一点:
string _Path = Path.GetFullPath(mPath);
Uri path = new Uri(_Path);
string indexingPath = path.AbsoluteUri;
CSearchManager csm = new CSearchManager();
CSearchCrawlScopeManager manager = csm.GetCatalog("SystemIndex").GetCrawlScopeManager();
if (manager.IncludedInCrawlScope(indexingPath) == 0)
{
manager.AddUserScopeRule(indexingPath, 1, 1, 0);
//add files and folders to content index
DirectoryInfo dinfos = new DirectoryInfo(_Path);
var targetFiles = dinfos.EnumerateFiles("*.txt");
File.SetAttributes(medicalDicPath, (File.GetAttributes(_Path) & ~FileAttributes.NotContentIndexed));
Parallel.ForEach(targetFiles, targetFile => { File.SetAttributes(targetFile.FullName, (File.GetAttributes(targetFile.FullName) & ~FileAttributes.NotContentIndexed)); });
manager.SaveAll();
}