If I have a filepath or stream, is there a static method I can use to determine whether the file/stream is a package, other than by trying to use Package.Open on the file/stream and catching the System.IO.FileFormatException?
Is there a way to determine whether a file can be opened as a System.IO.Packaging.Package?
237 Views Asked by ThunderFrame At
1
There are 1 best solutions below
Related Questions in C#
- Passing arguments to main in C using Eclipse
- kernel module does not print packet info
- error C2016 (C requires that a struct or union has at least one member) and structs typedefs
- Drawing with ncurses, sockets and fork
- How to catch delay-import dll errors (missing dll or symbol) in MinGW(-w64)?
- Configured TTL for A record(s) backing CNAME records
- Allocating memory for pointers inside structures in functions
- Finding articulation point of undirected graph by DFS
- C first fgets() is being skipped while the second runs
- C std library don't appear to be linked in object file
- gcc static library compilation
- How to do a case-insensitive string comparison?
- C programming: Create and write 2D array of files as function
- How to read a file then store to array and then print?
- Function timeouts in C and thread
Related Questions in .NET
- Does compiler optimize operation on const variable and literal const number?
- What is the point of definnig Asp.net Intrinsic Objects In different places and what is the different betwen them?
- Deleting Orphans with Fluent NHibernate
- IOrderedEnumerable to vb.net IOrderedEnumerable Conversion
- What is this namespace ITypeOfObjectsBoundToListBox ? Couldn't find it
- .net rest service with JSON string and consumed with java client
- What is best way to check if any of the property of object is null or empty?
- Telerik's WPF RadColorPicker NoColorText property not working
- Possible consequences of duplicate ProgId for different classes
- How are multiple requests to Task.Run handled from a resource management standpoint?
- Optimizing C++ call from C#
- Make a per-web-application object available to Web API and SignalR controllers
- System.ComponentModel.DataAnnotations.Schema namespace conflict
- LINQ Except/Distinct based on few columns only, to not add duplicates
- Not displaying content by its URL string - absolute urls
Related Questions in FILE
- Saving FileSystemInfo Array to File
- C programming: Create and write 2D array of files as function
- How can I change a specific line in a file with node js?
- Grabbing Edits from two strings
- In Android, would it be possible to open a file in the 'values' folder and to read its content?
- Using paths bonded to a XCode project to be shared
- Why am i getting these invalid characters before my file data?
- Optimum directory structure for large number of files to display on a page
- C Reading binary file with fread()
- Renaming a File() object in JavaScript
- How to write the current time to a new line of a .txt file on php execution
- introduce c++ into html
- How can I create a simple text file on a windows phone (8.1) that can be accessed trough USB cable?
- Pop-up and download zip file in ASP.NET
- Using access() in C
Related Questions in STREAM
- Extract bytes of specific stream from mpegts file using ffmpeg
- In Java how to read the latest string of constantly generated stream fast?
- java update all children in list
- Java - Start Upload after Download
- how to write the output of iostream to buffer, python3
- How to display MJPEG-stream in Vaadin (Java)?
- Creating a Command Prompt
- Unchecked returned value causing unexpected states and conditions
- Multiple streams over single project in Git?
- encode, decode base64 image stream delphi
- Java - Write a string prefixed with the 7 bit encoded length
- How I can send a object from Client to Server in Java?
- character encodings used by FileWriter, DataOutputStream, OutputStreamWriter and RandomAccessFile
- How do I save the console output to a textfile in a certain directory?
- Issues parsing a 1GB json file using JSON.NET
Related Questions in SYSTEM.IO.PACKAGING
- C# - Using protobuf to write directly into a zip file
- Is there a way to determine whether a file can be opened as a System.IO.Packaging.Package?
- Will PackageDigitalSignatureManager.VerifySignatures() lead to a call outside the network?
- c# Problem with my Xpath? Parsing Xml from a DocX file using Package.GetPart
- Get and set a package stream in password-protected OOXML files
- System.IO.Packaging Missing Override in [Content_Types].xml file
- ASP.Net : system.io.packaging package "File contains corrupted data"
- Create a Stream without having a physical file to create from
- How to use System.IO.Packaging in MonoTouch
- Extracting files from a Zip archive programmatically using C# and System.IO.Packaging
- Android error: Error generating final archive: java.io.FileNotFoundException:
- Unable to determine the identity of domain using System.IO.Packaging
- Tutorials on Open Packaging Conventions / System.IO.Packaging
- Is there a Java library equivalent to Microsoft/.NET System.IO.Packaging?
- Is it possible to NOT store the folder structure when creating a zip with the package class?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
You can either attempt to open the file as a .zip file and then look for metadata (thus implementing part of the package specification where you verify the package format) or you can just use
Open()and catch any potential exception. (The .docx / .xlsx / etc. formats are just ZIP files that follow a certain structure.)You can try reading the ZIP header but that will only verify that the file is a ZIP file - I'm not sure this buys you much (if anything).
My guess is that trying to open the file and catching the exception is the easiest route to go - if the specification changes your code will keep working. If you roll your own code to verify the file format, you'll have to keep maintaining it.