Johnnnnnnnnnnnnny
New member
- Joined
- Nov 3, 2022
- Messages
- 4
- Programming Experience
- Beginner
Hi Gents,
I have a specific requirement is to get a valid stream(which will be further operate) from given zip path?
The situation is use a support code snippet to determine given path is xml/zip file(one of these files inside zip is xml which what I want), if it's a xml then easily get a FileStream otherwise if it's a zip, then get Stream from zip(FileStream would be perfect but I've been tring FileStream but no solution).
To be more clear to the requirement, I came up with a current code to better explain what my point is:
I use stream = entry.Open(); but I can only get a DeflateStream which I can't use it further out of if{} statement.
Now All I want is how to change this code to get a valid(perfectly FileStream) Stream which contains the data in xml file that I can technically use it from there.
Regards,
Johnny
I have a specific requirement is to get a valid stream(which will be further operate) from given zip path?
The situation is use a support code snippet to determine given path is xml/zip file(one of these files inside zip is xml which what I want), if it's a xml then easily get a FileStream otherwise if it's a zip, then get Stream from zip(FileStream would be perfect but I've been tring FileStream but no solution).
To be more clear to the requirement, I came up with a current code to better explain what my point is:
example:
// I use hardcoding input path as an example here
public string iptPath = "D:\CSharp\compressFile\exampleZip.zip";
private FileStream stream;
// Check if given path a zip
if(Path.GetExtension(iptPath).EndsWith(".zip"))
{
if (iptPath is not null)
{
using var fileZipArchive = ZipFile.OpenRead(iptPath);
// Here I know there will be only one xml file inside zip.
var entry = fileZipArchive.Entries.Where(e => e.Name.EndsWith(".xml")).FirstOrDefault();
stream = entry.Open() as FileStream;
// Or I actually still get nothing if I typed code below
// var streamZip = entry.Open();
}
}
else
{
// This is goping to be purely xml file, as an example it should be "D:\CSharp\compressFile\exampleXml.xml";
stream = File.OpenRead(InputFile!);
}
I use stream = entry.Open(); but I can only get a DeflateStream which I can't use it further out of if{} statement.
Now All I want is how to change this code to get a valid(perfectly FileStream) Stream which contains the data in xml file that I can technically use it from there.
Regards,
Johnny
Last edited: