As I’m sure many of you know who have done development on Windows Phone, there isn’t built in support for compression and decompression. Many folks have pointed to the SharpCompress project on CodePlex, and this is what I ended up using for it as well. The BIG thing that was missing from it though has been any documentation whatsoever for decompressing files on the phone. I had quite a bit of code I had written for a winform application that used the WriteAllToDirectory method to decompress a zipped file on Windows. However, that method doesn’t exist in the assembly for Windows Phone. In addition, you can’t just provide the path to which you can unzip when using the Windows Phone assembly for SharpCompress, you have to give it a stream object.
This ultimately worked, but requires you to do things quite a bit differently from when you use this on the full version of Windows. Here are some tips to get you through this:
1. Enumerate through the Entry collection of the IReader you get from the Reader factory:
//"sr" is a stream reader object from previous code that contains the byte array of the actual zip file
using (var reader = ReaderFactory.Open(sr))
{
while (reader.MoveToNextEntry())
{
//IsDirectory always returns false in everything I've seen so far
if (!reader.Entry.IsDirectory)
{
//process the entry, described next
}
else
{
//do not know of a scenario where we can end up here
Debug.WriteLine(reader.Entry.FilePath);
}
}
}
2. Create the directory(s) for the files, then get an IsolatedStorageFileStream instance to which you can write:
//IsDirectory always returns false in everything I've seen so far
if (!reader.Entry.IsDirectory)
{
IsolatedStorageFileStream theFile = GetLocalFile(reader.Entry.FilePath);
}
private IsolatedStorageFileStream GetLocalFile(string fullPath)
{
IsolatedStorageFileStream fs = null;
try
{
//get isolated storage so we can create directories and decompress
IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication();
//trim everything from the last index of /, which is the file
//name, i.e. it will look like folder/folder/folder/filename.txt
string dirPath = fullPath.Substring(0, fullPath.LastIndexOf("/"));
//what's nice is you can create the full folder path in one call
if (!storage.DirectoryExists(dirPath))
storage.CreateDirectory(dirPath);
//now that all the directories exist, create a stream for the
// file – again, cool because you can just give the full path
fs = storage.CreateFile(fullPath);
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
return fs;
}
3. Now that you have a stream, you can write the individual file out use the WriteEntryTo method:
if (!reader.Entry.IsDirectory)
{
IsolatedStorageFileStream theFile = GetLocalFile(reader.Entry.FilePath);
if (theFile != null)
reader.WriteEntryTo(theFile);
}
Hope this helps someone, the lack of documentation was troublesome so I just had to puzzle through it.
Tao http://dichvuketoanlongbien.com/
Rủa
http://dichvuketoanlongbien.com/a2-96-dich-vu-ke-toan-tron-goi.html
Thằng http://dichvuketoanlongbien.com/a2-98-dich-vu-ke-toan-thue.html
Cờ
http://dichvuketoanlongbien.com/a2-103-dich-vu-bao-cao-tai-chinh.html
Hó http://dichvuketoanlongbien.com/a2-97-dich-vu-quyet-toan-thue.html
Nào
http://dichvuketoanlongbien.com/a2-114-dich-vu-ke-toan-tai-29-quan-huyen.html
Soi
http://dichvuketoanlongbien.com/i780-dich-vu-ke-toan-thue-tron-goi-tai-bac-ninh.html
Tài
http://dichvuketoanlongbien.com/i779-dich-vu-ke-toan-thue-tron-goi-tai-bac-giang.html
Khoản
http://dichvuketoanlongbien.com/i778-dich-vu-ke-toan-thue-tron-goi-tai-phu-tho.html
Và
http://dichvuketoanlongbien.com/i781-dich-vu-ke-toan-thue-tron-goi-tai-hung-yen.html
Link
http://dichvuketoanlongbien.com/i782-dich-vu-ke-toan-thue-tron-goi-tai-vinh-phuc.html
Của
http://dichvuketoanlongbien.com/i783-dich-vu-ke-toan-thue-tron-goi-tai-hai-phong.html
Tao. http://www.trungtamketoan.com.vn/
Chúng
http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-ha-noi.html
Mày
http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-tp-hcm.html
Đủ
http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-quang-ninh.html
Trình
http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-hai-duong.html
Thì
http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-bac-giang.html
Tự
http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-bac-ninh.html
Đi
http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-hai-phong.html
Mà
http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-nam-dinh.html
Làm.
http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-thai-binh.html
Việc
http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-thanh-hoa.html
Gì
http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-vinh-phuc.html
Phải
http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-hung-yen.html
Rẻ
http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-phu-tho.html
Rách
http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-binh-duong.html
Như http://www.tosvn.com
Thế. http://iketoan247.blogspot.com
Loại http://tailieuveketoan.blogspot.com
Chó http://mauhinhnendep.blogspot.com
Má. http://www.tosvn.com/search/label/Hack%20CF
Tao http://www.tosvn.com/search/label/Hack%20AvatarStar
Rủa http://www.tosvn.com/search/label/Hack%20Warcraft-Dota2
Những http://hocketoan360.com/category/tai-lieu-ke-toan/
Thằng http://iketoan247.blogspot.com/search/label/thong-tin-kinh-te
Soi http://iketoan247.blogspot.com/search/label/tin-bai-ve-thue
Tao http://hoclamketoan.edu.vn/
Sẽ http://hoclamketoan.edu.vn/category/khoa-hoc-ke-toan
Tan http://hoclamketoan.edu.vn/category/dich-vu-ke-toan
Cửa http://hoclamketoan.edu.vn/category/hoc-lam-ke-toan
Nát http://hoclamketoan.edu.vn/category/tai-lieu-ke-toan
Nhà http://hocketoan360.com/
Haha http://hocketoan360.com/category/khoa-hoc-ke-toan/
http://hocketoan360.com/category/dich-vu-ke-toan/