Quantcast
Channel: Active questions tagged filereader - Stack Overflow
Viewing all articles
Browse latest Browse all 105

How can I fetch metadata or file version (properties details section) of a file on client side?

$
0
0

I am trying to get dll file version on client side only.

Writing code on Angular 16 (2+), any solution on ts/js would work.

I tried using DataView and couple of solutions i found online, though they are returning file version though it is not correct.

onSelectFile(event: any) {  const file2: File = event.target.files[0];  this.readFile(file2);}readFile(file: File) {  const reader = new FileReader();  reader.readAsArrayBuffer(file);  reader.onload = (e: any) => {    const arrayBuffer = e.target.result;    const version = this.extractVersion(arrayBuffer);    console.log('DLL Version:', version);  };}extractVersion(arrayBuffer: ArrayBuffer): string {  const dataView = new DataView(arrayBuffer);  // Get the offset of the version information  const versionOffset = dataView.getUint32(60, true);  // Read the version information from the specified offset  const majorVersion = dataView.getUint16(versionOffset + 8, true);  const minorVersion = dataView.getUint16(versionOffset + 10, true);  const buildNumber = dataView.getUint16(versionOffset + 12, true);  const revisionNumber = dataView.getUint16(versionOffset + 14, true);  // Construct the version string  const version = `${majorVersion}.${minorVersion}.${buildNumber}.${revisionNumber}`;  // Print the version  return version;}

Output I am getting for dll Version is: -

DLL Version: 58052.49828.0.0

If I check the properties and go to details tab, version is something else: -

enter image description here

Can I know, how to extract the correct fileversion on client side either using DataView or any other class/library?


Viewing all articles
Browse latest Browse all 105

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>