Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenXML documents, how do you know which is which, when there is no extention
    primarykey
    data
    text
    <p>What i have done for now, and which works is this:</p> <pre><code>private string DetermineOpenXML(string file) { try { SpreadsheetDocument doc = SpreadsheetDocument.Open(file, false); doc.Close(); return ".xslx"; } catch { try { WordprocessingDocument doc = WordprocessingDocument.Open(file, false); doc.Close(); return ".docx"; } catch { try { PresentationDocument doc = PresentationDocument.Open(file, false); doc.Close(); return ".pptx"; } catch { return string.Empty; } } } } </code></pre> <p>I think there must be a better way to see what kind of file it is other than just trial and error. The thing is, i am working on a small program, that finds out what file extension files should have. The reason i do this is because i have the files from a database, where they are saved sometimes without extension and other times with a wrong extension.</p> <p>What i have done with these files is that i found out that all OpenXML documents share the same File signature: "50 4B 03 04 14 00 06 00", which is close to a signature of a zip file, and i can also open OpenXML files with a zip program and see its content. And maybe this is the solution i should go for, i was just hoping that it would be faster / easier to use OpenXML SDK and that it had a property or something that could check it for me.</p> <p>Edit: I have added a answer, i would still like to see if there was a better solution, even though there it works for my current purpose. It does not take in for account that the extensions should have been template files.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload