Check file header before / after upload

Hello, 

I want to check the file header before ( or after ) I upload an Attachment ( File )
to an Sharepoint Item. 

Is there a way/solution to read the file header ( hex read ) ?

Based on the information I get from the "stream" I want to classify
the file/attachment in sharepoint ( e.g. wrong header / correct header )

Second solution:
I could also upload all files and the run a "check header tool" within Sharepoint.
Is this possible ?

Regards,
Steve

August 25th, 2015 5:24am

Hi,

You can try to identify the extension of the file through event receiver before and after upload.

Try this, are you looking for this ?

var extension = Path.GetExtension(FileStreamObj.Name);

Free Windows Admin Tool Kit Click here and download it now
August 26th, 2015 1:23am

Hi, thank you, this would get the extension of the file...

But I want to read the header of the (binary) file, 
I need "something" to stream the file, then look for the characters
in the stream...

Based on different headers I want to classify the file ( set a field in sharepoint ),
but this is secondary task.

Is there somehow a function ( with Sharepoint Services or Javascript or C# )
to read the binary header?

Best regards
Steve

August 26th, 2015 2:55am

Hi,

Are you trying to read the contents  of the file for scanning the specific keyword before upload Or after upload ?

if yes, here is code snippet

string contents;
using(var sr = new StreamReader(fileStream))
{
   contents = sr.ReadToEnd();
}

Now you can check the content string, if your condition met add your logic to add the file to Document Library.


Free Windows Admin Tool Kit Click here and download it now
August 26th, 2015 3:09am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics