Is there any way for me to read contents of an xml file in a cab file in C#? I know how to use XDocument to load an xml file and read its contents, but not sure if it is possible to read an xml file that is zipped up in a cab file.
Any ideas?
What you are looking to do is to extract the contents of the CAB file first. You can either write the code to do that yourself or use a 3rd party library.
I have not used this personally, but I have seen it mentioned several times on this site and others: http://www.codeproject.com/KB/files/CABCompressExtract.aspx
To take a stab at writing it yourself, refer to the documentation here: http://msdn.microsoft.com/en-us/library/cc483132%28EXCHG.80%29.aspx
Related
I have an application which allows uploading a ppt/pptx file. I want to convert the presentation file to equivalent XML format.
A pptx file is essentially a zip file, renamed to pptx. If you rename and extract the content you can find the xml document.
With ppt you have more problem as it is proprietary to Microsoft and may not even be publicly documented. Office automation would most probably work, but rather complicated.
I have an .odt wordprocessing file, to be processed with libre office or Word, and I need to replace a bunch (20+) of strings in the text with other text.
I know an .odt file is really a .zip file, containing .xml files and that i need to access content.xml.
Do I unzip the content.xml to a stream, deserialize that and use LINQ or something?
Or is there an easier way, using some ready-made library?
If you're using .Net 4.5 you can make use of the new System.IO.Compression namespace. There are a couple articles out there on how to do it. Here's one http://www.codeguru.com/csharp/.net/zip-and-unzip-files-programmatically-in-c.htm
which I've found useful.
I need to read, modify and then write from/to an xml file in a zip I need to do this for lots if files as the xml is kind of an index for what the zip is for.
Saxon 9.5 implements the EXPath ZIP file extensions: take a look, it might do what you need.
I am working on an application which has to retrieve data from a CSV file online
and display it with a click of a button. However, how can I automatically store
the CSV file in a safe place where I can access the information? I am working with Visual Studio C#.
Thank you.
You want to use the WebClient class to make an http request to the server for the csv file. It should read the whole contents as a string which you can then parse and manipulate at your leisure.
http://msdn.microsoft.com/en-us/library/system.net.webclient(VS.100).aspx
Use System.IO.File to write the contents to a file.
http://msdn.microsoft.com/en-us/library/system.io.file.aspx
The FileHelpers are a free and easy to use .NET library to import/export data from fixed length or delimited records in files, strings or streams.
The FileHelpers Library
http://www.filehelpers.com/
I want to get the type of file uploaded using the ASP.NET FileUpload control. When I upload a file, I want to be able to get the type of file uploaded, so I can assign a an icon to the file (such as a word, excel, pdf icon).
Here is the problem, I can't go off the file extension because a file could be called test.xxxxxxxx and be a valid pdf file, or a file might not have an extension.
The other option is to read the content-type, but with some of these appear not to be standard or in a simple to read format such as excel files, so is there another option to determine the file type?
I would review the process that names a PDF file "test.xxxxxxxx" without a ".pdf" extension. Most workflows that files have some kind of naming convention (manual or automated)
If you cannot read the extension, the file format will need to be detected by interogating markers that make it a known file format: eg: if the stream starts with or contains "%PDF" its a PDF.
If you don't know the extension, then you would have to know the file format of popular file types and then read the file and see if it matches one of your known formats. That doesn't sound optimal, though.
An easy way to check the true type of a file server side, using System.IO.BinaryReader, is described here:
http://forums.asp.net/post/2680667.aspx
and VB version here:
http://forums.asp.net/post/2681036.aspx
You'll need to know the binary 'codes' for the file type(s) you're checking for, but you can get those by implementing this solution and debugging the code.
Also note that when the BinaryReader is closed with the r.Close() statement, this will make FileUploader.HasFile = False