c# uwp read csv from web - c#

I am trying to make an app that make use of open data.
The data I try to read out is in a CSV format (and is about 40mb big).
I have 2 problems I can't solve.
First I having difficulties to read the file from the web.
I already read on MSDN how to read files asynchrome but it's all about local files. I want to make a list of objects. Each line (except the first line) contains all props for 1 object
Secondly when I finally managed to read the file, is there a way to save it's data and read it somehow the next time? Because 40mb is pretty big to re-download each time you open the app and it takes a lot of time.
I was wondering if it is possible that when I read the the file on the web again, it will only read and at the new lines.
I am a newbie in UWP (c#) applications, so my apologies for the questions.
Thanks in advance.

There are two APIs you can use to download a file. One is HttpClient, described here on MSDN Documentation and in a UWP sample here. This class is usually recommended for smaller files and smaller data, but can easily handler larger files as well. Its disadvantage is, that when the user closes the app, the file will stop downloading.
The alternative is BackgroundDownloader, again here on MSDN and here in UWP samples. This class is usually recommended for downloading larger files and data, as it automatically perfroms the download in the background so the download will continue even when the app is closed.
To store your files, you can use the ApplicationData.Current.LocalFolder. This is a special folder provided to you by the system for storage of application files. You have read/write access to this folder and you can not only store your files here, but even create subfolder structure using UWP StorageFile and StorageFolder APIs. More about this is on MSDN.

Related

Best way to package large numbers of large files for download?

I have an ASP.NET website that stores large numbers of files such as videos. I want an easy way to allow the user to download all the files in a single package. I was thinking about creating ZIP files dynamically.
All the examples I have seen involve creating the file before it is downloaded but potentially terabytes of information will be downloaded and therefor the user will have a long wait. Apparently ZIP files store all the information regarding what is in the ZIP file at the end of the file.
My idea is to dynamically create the file as its downloaded. This way I could allow the user to click download. The download would start and not require any space on the server to be pre packaged as it would copy things over uncompressed sequentially. The final part of the file would contain the information on the contents of what has been downloaded.
Has anyone had any experience of this? Does anyone know a better way of doing this? At the moment I cant see any pre made utilities for doing this but I believe it will work. If it doesn't exist then i'm thinking that I will have to read the Zip file format specifications and write my own code... something that will take more time than I was intending to spend on this.
https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT

How to create a resource (text file) from c# code? Or can we edit an existing resource file?

I have built a web application with vacations period planning (didactic purpose).
I need to import a text file with bank holidays once a year (the file will be uploaded in UI).
(ex: localPath/BankHolidays.txt - contains: 1.01.2015,31.12.2015,...).
I thought it would be a good approach to save the given text file as a Resource file instead of saving it somewhere else (in ProjectDir) as a normal .txt file. Because I need to access this file quite often and I don't think it's necessary to save this information in a db...
Is this a really good approach in my case?
If it is, how can I save a file in Resources dynamically from my code?
Have a look at the resourceWriter class on the MSDN:
http://msdn.microsoft.com/en-us/library/system.resources.resourcewriter.aspx
This class will perform all of the heavy lifting in terms of file I/O and data formatting. There is also a great tutorial on how to actually use it at:
http://www.c-sharpcorner.com/UploadFile/yougerthen/105232008045338AM/1.aspx

Where does file information (like DateCreated) get stored when you create a new file?

Suppose that I would like to add extra information about a file, without writing that information as content of that file. How would I do this? A couple of good examples are:
With Word documents, you can add Author tag to a document. And,
MP3 files have lots of info stored inside of them but when you play the file, you don't see that info (unless the program playing the file has been programmed to display that information).
How does Windows do this?
This information is stored in the file system (on windows - NTFS).
In NTFS, you can actually store another file, as part of this information, and it stores much more information about each file than you may expected.
NTFS file streams
Exapmle in C how to consume them
About MP3 and word - In these cases the information is stored inside the file, as part of its format.

File upload / did I make a mistake choosing vb.net instead of php?

for the past 3 days I've been trying to create an upload system for multiple files, possibly large, with progress bars.
I've been roaming the web relentlessly for the past few days, and I can say, I am now familiar with most difficulties.
sadly, all the solutions I've found online are not written c# or vbscript, in fact most of them are written in php.
I wouldn't mind switching to another language but the entire website is written in vb.net and for the sake of coherence I thought it might be best to keep with it.
File uploads:
Problem 1 - progress bar:
I understand file uploads will not work with ajax, since the ajax response will only occur after the file had completed its upload.
I understand there is a solution using iFrames but I cannot seem to find any online examples (preferably using vb.net or c#).
I understand there is another alternative using flash. how???
I also understand people are mostly against using iframes but I can't find what the reason might be.
Problem 2 - Multiple Files:
I can have multiple file support with HTML5. great, but IE doesn't support it? well... IE users will just have to upload one file at a time.
Problem 3 - Large files:
how?
I heard something about chunking, and blobs, but these are still just random gibberish words for me. can somebody explain, the meaning and the implementation?
references to reading material are much appreciated even though, if it's on the web, I've probably already read it in my search for my solution.
#DevlshOne has a decent thread with some good information.
Here are the three basic requirements for what I did:
Create Silverlight app for clientside access and upload control. (use app of your choice)
Create an HttpHandler to receive the data in chunks and manage requests.
Create the database backend to handle the files.
Silverlight worked well because I was already in VB (ASP.NET). When used in-browser, as opposed to out-of-browser, the ASP.NET session was shared with Silverlight, so there was no need to have additional security/login measures. Silverlight also allowed me to limit what file types could be selected and allow the user to select multiple files from the same folder.
The Silverlight app grabs the files selected by the user, displays them for editing of certain properties, and then begins the upload when the user clicks the 'upload' button. This sets off a number of threads that each upload chunks of data to the httphandler. The HttpHandler and Silverlight app send and receive in chunks, with the HttpHandler always sending an OK or ERROR message when the request has been processed for the uploaded chunk.
Our specific implementation of file uploading also required some database properties (fields) to be filled out by the user, so we also had inputs for those properties and uploaded them to the server with the file data.
An in-browser Silverlight app can also have parameters passed into it through the html, so I do this with settings like 'max chunk size' or 'max thread count'. I can change the setting in the database and have it apply to all users.
The database backend is basically a few stored procedures (insert your data management preference here) that control the flow of the logic. One table holds completed files (no file data), and a second holds the temp files that are in progress of being uploaded. One stored procedure initiates a new file record in the temp table and processes additional chunk uploads, and another controls the migration of the completely uploaded file from the temp table to the completed table. (A piece of VB code in the HttpHandler migrates the actual binary file data from the temp table to a physical file.)
This seems pretty complex, but the most difficult part would be the interaction with the handler and passing the chunks around (response/requests, uploading successive chunks, etc.). I left out a lot of information, but this is the basic implementation.

Play embedded video resource as stream

EDIT: I changed my question to better clarify the issue.
How is it possible to play a video from a byte array (taken from embedded resource) using DirectShow.Net library?
Since I'm going to prevent users from accessing the video file, I need to embed the video file as resource and play it.
Thanks in advance.
It's a bit non-standard, but you could use something like WCF to self-host an endpoint inside your desktop application. Then set the source of the video input to be the "URL" to your self-hosted endpoint. That would work for WPF or WinForms. Not sure about Silverlight though.
The self-hosted endpoint could pull the media from your embedded resources and stream it from there.
It sounds to me like the problem is not so much how to use the DirectShow library (the `DirectShow.Net Forum is specifically designed for that), but rather how to use an embedded resource.
I ran into something similar a few years back on a contract job where an employer was worried that some customer might steal his proprietary information. My information was in hundreds of PDF documents, but the idea works the same for video files.
Here's how I tackled the problem:
First, place the video file in your list of resources: I use Visual Studio, so I go to the Project's Properties, click the Resources tab, select the Files option, then select Add Resource > Add Existing File...
Add the following two namespaces to the code file you will be using:
using System.IO;
using System.Diagnostics;
Finally, where you want to play your video file, just do something similar to the following:
Process player = null;
string tempFile = "~clip000.dat";
try {
File.WriteAllBytes(tempFile, Properties.Resources.MyMovie_AVI);
player = Process.Start(tempFile);
player.WaitForExit();
} finally {
File.Delete(tempFile);
}
Most likely, you will not be calling the Process.Start method, but rather the appropriate DirectShow method. The idea is still the same: Extract your resources as a byte array, write them to a new, temporary file, use the file, then delete that file whenever you are done.
Be sure to put the Delete statement in the finally block so that if any errors occur or your user closes the program while the file is still playing, your application still cleans up the old file.
EDIT:
I think this might be a viable way of doing this:
using (MemoryStream ms = new MemoryStream(Properties.Resources.MyMovie_AVI)) {
// Now you have to find a way in `DirectShow` to use a Stream
}
Can you use a different library?
I used the WPF MediaKit to do some non-standard streaming of a secure, live h264 video stream. The developer (Jermiah Morill) was very responsive, and the customization I could perform was extensive (since you get the source).
At that point, you could embed the video as an embedded resource, load the byte array (perhaps either part of it at a time or the entire file) into memory, and play from memory.

Categories

Resources