ZipArchive not working for Universal App (Windows 8.1 and Windows Phone 8.1) - windows-8

Hi i have this problem in ZipArchive for my universal app. The code below works fine for the Windows Phone but not for the Windows 8.1 app.
I can'nt see why this is not working for the Windows 8.1 app, but only for the Windows Phone
The Exception i get is this: "Number of entries expected in End Of Central Directory does not correspond to number of entries in Central Directory." when i try to read the entries.
using (var zipStream = await folder.OpenStreamForReadAsync(filename))
{
using (MemoryStream zipMemoryStream = new MemoryStream((int)zipStream.Length))
{
await zipStream.CopyToAsync(zipMemoryStream);
using (var archive = new ZipArchive(zipMemoryStream, ZipArchiveMode.Read))
{
try
{
// THIS CAUSE THE EXCEPTION!!!!
foreach (var entry in archive.Entries)
{
if (entry.Name == "")
{
// Folder
await CreateRecursiveFolder(folder, entry);
}
else
{
// File
await ExtractFile(folder, entry);
}
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
//throw;
}
}
}

Related

Cannot Resolve Symbol GetAccessControl in .NET Core 3.1

I am trying to write a function in .net core 3.1 Class Library, to check file user rights.
Unfortunately, .net core 3.1 does not recognize GetAccessControl.
I have attached NUGET
System.IO.FileSystem 4.3.0
Microsoft.Windows.Compatability 7.0.0
Nothing works so far.
public static bool CheckFileAccess(string path, string domainUser)
{
var result = false;
try
{
using (FileStream file = new FileStream("path", FileMode.Open))
{
var acl = File.GetAccessControl(file.Name);
// do something with the acl
var rules = acl.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount));
foreach (FileSystemAccessRule rule in rules)
{
if (rule.IdentityReference.Value.Equals(domainUser, StringComparison.OrdinalIgnoreCase))
{
return true;
}
}
}
Console.WriteLine("User does not have access to the file.");
}
catch (UnauthorizedAccessException ex)
{
return result;
}
return result;
}

How to Dowload files in React-Native UWP application

I am new in reactnative mobile application development. I need to download file from webservice url in windows UWP. I checked with react-natived-fs and rn-fetch-blob its working only in android and ios. In windows UWP how can i achieve this download files.. Any one please help me.
i just write a bridge for this. now its working fine. For download i did
[ReactMethod]
public async void download(string fileName, JObject _, IPromise promise)
{
try
{
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
StorageFolder docFolder = KnownFolders.DocumentsLibrary;
string folderName = "DMSFolder";
StorageFile file = await localFolder.CreateFileAsync("sample1.pdf",CreationCollisionOption.ReplaceExisting);
StorageFile docfile = await docFolder.CreateFileAsync("sample1.zip",CreationCollisionOption.ReplaceExisting);
var cli = new HttpClient();
var uriBing = new Uri(#fileName);
Byte[] bytes = await cli.GetByteArrayAsync(uriBing);
IBuffer buffer = bytes.AsBuffer();
await Windows.Storage.FileIO.WriteBufferAsync(file, buffer);
await Windows.Storage.FileIO.WriteBufferAsync(docfile, buffer);
if (file != null)
{
promise.Resolve(null);
}
else
{
promise.Reject(null, "File Copied failed.");
}
}
catch (Exception e)//FieldAccessException
{
Console.WriteLine("Exception occured====>" + e);
promise.Reject(null, fileName, e);
}
}

Windows Phone 8.1 PDF viewer

I'm trying to create an windows phone 8.1 app in which the user opens a pdf file from a link. Let's say i want to open this pdf file from the link below inside my app at the press of a button, without downloading the file locally.
http://www.analysis.im/uploads/seminar/pdf-sample.pdf
Can this be done with WebView ? The idea is that the user will pass through a list of pdf files stored online and choose one to save locally.
Windows phone 8.1 webview does not support native pdf rendering.
You can look at Mozill pdfJS. Hope it helps.
I am not sure about WebView, but you can render the PDF from the URL natively in the app.
You can created a streamed file, and feed that file to the PDF renderer provided by the Windows.Data.PDF It works fairly well. Check my post here for a detailed tutorial
public PdfDocument Document { get; set; }
public PdfPage CurrentPage { get; set; }
Create streamed file -
try
{
IRandomAccessStreamReference thumbnail = RandomAccessStreamReference.CreateFromUri(new Uri(webURL));
StorageFile file1 = await StorageFile.CreateStreamedFileFromUriAsync("temp.pdf", new Uri(webURL), thumbnail);
this.Document = await PdfDocument.LoadFromFileAsync(file1)
}
catch (Exception ex)
{
MessageDialog dialog = new MessageDialog(ex.Message);
dialog.ShowAsync();
return;
}
for (int i = 0; i < Document.PageCount; i++)
{
await this.RenderPage(i);
}
Render the pages -
private async Task RenderPage(int index)
{
this.CurrentPage = this.Document.GetPage((uint)index);
using (IRandomAccessStream stream = new MemoryStream().AsRandomAccessStream())
{
await this.CurrentPage.RenderToStreamAsync(stream);
BitmapImage source = new BitmapImage();
source.SetSource(stream);
Image i = new Image();
i.Source = source;
i.Margin = new Thickness(0,5,0,0);
PagePanel.Children.Add(i);
}
}

Sqlite Database in windows phone 8 app

I'm new to windows app development.How can I make sqlite database in windows phone 8 app?This link shows how to use local databse but I want sqlite databse http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202876(v=vs.105).aspx
thanks in advance....
you can download a nuget package called sqlite for windows phone.
then you can a .db file in your project or can create a new by using following code.
public static SQLiteAsyncConnection connection;
public static bool isDatabaseExisting;
public static async void ConnectToDB()
{
try
{
StorageFile storageFile = await ApplicationData.Current.LocalFolder.GetFileAsync("DelhiMetroDB.db");
isDatabaseExisting = true;
}
catch (Exception ex)
{
isDatabaseExisting = false;
}
if (!isDatabaseExisting)
{
try
{
StorageFile databaseFile = await Package.Current.InstalledLocation.GetFileAsync("DelhiMetroDB.db");
await databaseFile.CopyAsync(ApplicationData.Current.LocalFolder);
isDatabaseExisting = true;
}
catch (Exception ex)
{
isDatabaseExisting = false;
}
}
if (isDatabaseExisting)
{
connection = new SQLiteAsyncConnection(Path.Combine(ApplicationData.Current.LocalFolder.Path, "DelhiMetroDB.db"), true);
}
}
}
}
then you can use this variable connection to connect with database like :
var result= classname.connection.QueryAsync<objecttype>("SELECT * FROM tablename").Result;

How to store save Thumbnail image in device in windows 8 metro apps c#

I am creating Thumbnail and showing in frame by using this code
Platform -> windows 8 metro apps using c#
http://code.msdn.microsoft.com/windowsapps/File-and-folder-thumbnail-1d530e5d
in windows 8 metro apps using c#. i need to save or Store ( in device )the thumbnail image which i am creating at run time. in DisplayResult() of constants.cs class file i need to save that image in device how to achieve this . please give me some idea or example i am very new in mobile and never worked on Image and thumbnails Part . Thanks in advance .
Try this. The below code will save picked audio file's album art in TempFolder
private async void btnPickFile_Click(object sender, RoutedEventArgs e)
{
string[] Music = new string[] { ".mp3", ".wma", ".m4a", ".aac" };
FileOpenPicker openPicker = new FileOpenPicker();
foreach (string extension in Music)
{
openPicker.FileTypeFilter.Add(extension);
}
StorageFile file = await openPicker.PickSingleFileAsync();
if (file != null)
{
await SaveThumbnail("MySongThumb.png", file);
}
}
private async Task SaveThumbnail(string ThumbnailName, StorageFile file)
{
if (file != null)
{
using (StorageItemThumbnail thumbnail = await file.GetThumbnailAsync(ThumbnailMode.MusicView, 100))
{
if (thumbnail != null && thumbnail.Type == ThumbnailType.Image)
{
var destinationFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync(ThumbnailName, CreationCollisionOption.GenerateUniqueName);
Windows.Storage.Streams.Buffer MyBuffer = new Windows.Storage.Streams.Buffer(Convert.ToUInt32(thumbnail.Size));
IBuffer iBuf = await thumbnail.ReadAsync(MyBuffer, MyBuffer.Capacity, InputStreamOptions.None);
using (var strm = await destinationFile.OpenAsync(FileAccessMode.ReadWrite))
{
await strm.WriteAsync(iBuf);
}
}
}
}
}
UPDATE 1
private async Task<StorageFile> SaveThumbnail(StorageItemThumbnail objThumbnail)
{
if (objThumbnail != null && objThumbnail.Type == ThumbnailType.Image)
{
var picker = new FileSavePicker();
picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
picker.FileTypeChoices.Add("JPEG Image", new string[] { ".jpg" });
picker.FileTypeChoices.Add("PNG Image", new string[] { ".png" });
StorageFile destinationFile = await picker.PickSaveFileAsync();
if (destinationFile != null)
{
Windows.Storage.Streams.Buffer MyBuffer = new Windows.Storage.Streams.Buffer(Convert.ToUInt32(objThumbnail.Size));
IBuffer iBuf = await objThumbnail.ReadAsync(MyBuffer, MyBuffer.Capacity, InputStreamOptions.None);
using (var strm = await destinationFile.OpenAsync(FileAccessMode.ReadWrite))
{
await strm.WriteAsync(iBuf);
}
}
return destinationFile;
}
else
{
return null;
}
}