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?
243 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
- file download method in visual studio 2017
- Repository manager receives the wrong connection string in .net core
- MongoDb not connecting C#
- The current .NET SDK does not support targeting .NET Core 6.0. Brand new WPF Project VS Community 2022 17.9.5
- Why Scanning GSI on DynamoDb doesnt work as fast as expected when using CONTAINS?
- Are "blittable types" really unmanaged types for StructLayout Sequential
- Failed to fetch dynamically imported module on Blazor JS Interop
- Problem to upload several images per one request
- Implementing Azure AD B2C Authentication in .NET 8 Blazor Project (RenderMode: InteractiveAuto)
- Stripe connect payout - throws exceptions
- 'IOException: The cloud file provider is not running', when trying to delete 'cloud' folder
- Azure Application Insights Not Displaying Custom Logs for Azure Functions with .NET 8
- Convert C# DateTime.Ticks to Bigquery DateTime Format
- Socket.io nodejs server .NET connection
- Producer Batching Service Bus Vs Kafka
Related Questions in FILE
- Helpt with reading files
- Why can't I use the file pointer after the first read attempt fails?
- Can't read the file using std::wifstream C++
- How can the scanner reread the entire file after it has already executed hasNextLine once?
- What is 'Invalid Load Key, '\x00'
- php $_FILE variable undefined index
- Data loaded from the file is not returned in the correct order
- File splitting and encryption
- Optimizing an s5cmd command that uses awk to generate a text file
- segmentation fault while reading in text file ( c++ )
- File.OpenText is adding C:\ to the front which is an error
- UTF-8 issue with excel
- How to upload files to MediaWiki APIs in Rust?
- No such file or directory: '/tmp/tmp_ejr26m6.upload.mp3' in Django
- Problems accessing zip files on the react front end from express backend
Related Questions in STREAM
- How to start a download and render a response without hitting disk?
- How to properly handle byte buffers from C to Ada?
- Color Thresholding JS, Average Image Color Detect JS
- FastAPI finish streaming function in StreamingResponse even if client closed the connection
- How can I connect to a websocket from a vue app that is exposed to the network (yarn dev --host)?
- PHP: How to get the Content-Length from stream request for chunk download
- How to handle errors inside a NodeJS stream?
- Python TCP Server that both sends and or receives data (independently) using asyncio streams?
- Efficient string replace in a stream
- Using polly to generate audio from LLM output
- Stream YAML output, rather than loading everything into memory
- Python: Creating Zip file from Minio objects results in duplicate entries for each file
- Node.js/Express File Download Returns 0-Byte Plaintext Files
- Stream data from server component in NextJS 14 App Router
- How to read from last position when logstream is interrputed
Related Questions in SYSTEM.IO.PACKAGING
- C#, System.IO.Packaging, Package.Open, System.IO.IOException when creating a file in device root
- Cannot get Uri for an in-memory object because of missing PackageStore class
- Get and set a package stream in password-protected OOXML files
- Digitally sign .xlsx file using System.IO.Packaging in c#
- How to fix 'Could not load file or assembly System.IO.Packaging, Version=4.0.3.0' in a .net standard 2.0 project
- openxml .net 4.5 lib with .net core 2.2
- c# Problem with my Xpath? Parsing Xml from a DocX file using Package.GetPart
- Add an arrow to a chart in Word by direct xml manipulation
- Adding a macro file to an XLSX/XLSM file using Packaging
- Getting "File contains corrupted data" exception while opening the XPSDocument Package
- Is there a way to determine whether a file can be opened as a System.IO.Packaging.Package?
- C# Getting a list of names of the webcams
- Store must be open for this operation - System.IO.Packaging.Package
- Is it possible to NOT store the folder structure when creating a zip with the package class?
- Zip package with Unicode chars in file name can't be uncompressed with System.IO.Packaging.Package?
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.