C#, Compress directory with files opened for other applications - c#

I'm working in a very basic C# application, I want to compress a directory that has some files (specifically a dbf database) that are already opened or in use for other software.
I use the class "ZipFile" in this way:
ZipFile.CreateFromDirectory(source, path);
And I get an exception that says that It could not access to the file because it was already in use for other application.
Is there another way to do this?
Thanks!

Related

Create the file before downloading and complete it after downloading by double tapping on it like OneDrive in c#

There is a feature in OneDrive that you can see a file that is on the OneDrive site on your system without actually having that file in your system. And when you double click on that file, that file starts to download and you can see its contents.
I want to implement such a possibility with C#.
I have a site where files are uploaded.
I download the files from there and put them in a folder on my C drive.
But I want that file not to be downloaded until it is double-clicked, something similar to OneDrive.
What should I do?
I compared the FileInfo of these two files, but I didn't see any difference and I couldn't find a solution for this problem.
This is a virtual filesystem implemented using a file system driver.
There are multiple ways to implement this feature using C/C++.
But in your case, using C# means you should use third-party libraries to create a virtual files system.
There is a library called Dokan, which lets you implement a full-featured virtual file system, and you have complete control over its behaviour in your C# project.
it called "Windows Shell namespace"
https://learn.microsoft.com/en-us/windows/win32/shell/namespace-intro
i used EZNameSpace Wrapper for handling this.
there is another library called "CBFS Shell" (formerly shelboost) that you can use.
You could create a dummy file that appears to be correct but is really just a pointer to some code that downloads the correct file. Then use File.Move or File.Copy to replace the dummy file with the actual file.

c# uwp read csv from web

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.

Open dropbox file with OpenFileDialog and dropnet c#

I’m creating a c# winforms desktop program with dropbox support. The problem comes in where the user must select the file (from dropbox) that he would like to open. Is it possible to use the OpenFileDialog to display the content of the person’s dropbox account? I know you can just direct the openFileDialog to the local dropbox folder, but I don’t want to do that. This will mean that the person must have dropbox installed on that computer before they can use this function of my program. If you can’t do this, how will you use tree and list views to create your own openFileDialog? I would like to keep the design the same as the standard openFileDialog. I have read that you can create a rapper class for customising the openFileDialog but don’t know how this will work.
I have looked on google but can’t find what I’m looking for. Any advice or examples will be appreciated.
I’m using dotnet 4.5 and the dropnet library.
Thank you
OpenFileDialog only shows existing files.
Your program can act like drop box client application and load all files to the client in a local folder. Then when you show the OpenFileDialog you can set that folder as InitialDirectory of the file dialog.
Also if you don't want to load all files, you can create dummy (empty) files on the local folder and after the user choose to show the file from OpenFileDialog, then download the file and show it to the user.

How do I programmatically locate my MEGAsync folder?

Using C#, I want to locate the local root folder where MEGAsync syncronizes into.
There are several similar questions for other clould providers:
How do I programmatically locate my Dropbox folder using C#?
How do I programmatically locate my Google Drive folder using C#?
How do I find the OneDrive (SkyDrive) and GoogleDrive folders without the API?
Still for MEGAsync I found no solution.
My question:
Is there any chance to find the MEGAsync folder without additional libraries?
Update 1:
There is a configuration file located at
C:\Users\MyUser\AppData\Local\Mega Limited\MEGAsync\MEGAsync.cfg
All the content seems to be encrypted. So I doubt that there is any solution at all.
I had the same question and I figured out that the MEGAsync.cfg file that you mention in your question is actually not encrypted, each entry is just encoded as base64. The format of each line is:
<key>=<base64_encoded_value>
You can decode each entry in the config file using C#'s "Base64" decoder, although I have only tested it with python.

upload file only to unzip it without writing file on server

In my asp.net aplication I would like to give the oportunity to the user to check on its local machine zip file. Then I would like to get this file on server(without saving it on the server) unzip it proceed and save proceeded data to database.
What should I do to accomplish this task? Thank You for any hints
I would use a zip library to read in the zip file stream and process the files contained inside. I have previously used SharpZipLib for this purpose before. See SharpZipLib Examples for more information.

Categories

Resources