如何读取扩展文件属性/文件元数据所以,我按照教程使用ASP.netcore将文件“上传”到本地路径,这里是代码:publicIActionResultAbout(IListfiles){foreach(varfileinfiles){varfilename=ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');filename=hostingEnv.WebRootPath+$@"{filename}";using(FileStreamfs=System.IO.File.Create(filename)){file.CopyTo(fs);fs.Flush();}}returnView();}我想读取文件的扩展属性(fileelementdata)like:并用这个数据对文件进行排序,有没有办法用Iformfile?如果你想访问更多的文件元数据,那么.NETframework提供ootb,我觉得你需要使用第三方库。否则,您需要编写自己的COM包装器才能访问这些详细信息。请参阅此链接以获取纯C#示例。以下是如何读取文件属性的示例:将“Windows/System32”文件夹中对Shell32.dll的引用添加到项目列表arrHeaders=newList();列表>属性=新列表>();Shell32.Shellshell=newShell32.Shell();varstrFileName=@"C:UsersAdminGoogleDriveimage.jpg";Shell32.FolderobjFolder=shell.NameSpace(System.IO.Path.GetDirectoryName(strFileName));Shell32.FolderItemfolderItem=objFolder.ParseName(System.IO.Path.GetFileName(strFileName));对于(inti=0;i(attrIdx,attrName,attrValue));Debug.WriteLine("{0}t{1}:{2}",i,attrName,attrValue);}控制台.ReadLine();您可以丰富此代码以创建自定义类,然后根据您的需要进行排序。那里有很多付费版本,但是有一个名为WindowsApiCodePack的免费版本,例如访问图像元数据,我认为它支持上面的内容是C#学习教程:如何读取扩展文件属性/文件元数据分享整个事情,如果对你有用,需要多了解C#学习教程,希望大家多多关注——ShellObjectpicture=ShellObject.FromParsingName(file);varcamera=picture.Properties.GetProperty(SystemProperties.System.Photo.CameraModel);newItem.CameraModel=GetValue(相机,String.Empty,String.Empty);varcompany=picture.Properties.GetProperty(SystemProperties.System.Photo.CameraManufacturer);newItem.CameraMaker=GetValue(公司,String.Empty,String.Empty);本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:
