Save File and Protect from User Writes - c#

I would like users to add files to a program, in a Windows Active Directory Environment. I would then like the program to save the files to a directory. However I would like to have the files saved to a directory where the user only has read access. Once the file is saved it is permanent and cannot be edited by the user, but they can still open it and save it locally with changes if desired.
This would be like saving the file with elevated permissions.
I don't think setting a read only attribute will do the trick as to my knowledge if the user finds the directory and file they could change that status manually. I also don't think System.IO.File has this kind of functionality.
Is there anyway to achieve this?

It seems FileIOPermission library could solve this porblem so use c# sharp libary which is "FileIOPermission", you can go over from this.

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.

Saving out multiple files in Windows Store

I have a windows store app that uses an internal file library hosted in localstorage. Is there anyway to export these en masse without needing to make the user choose a location / file name for each file?
I know I can zip them up and export the zip, but I was hoping to allow the user to choose a folder and then save a series of text files into that folder. Is this possible?
I'm not looking for someone to write my code for me, just point me in the right direction
Get the files in a List (from LocalStorage)
run a foreach loop (for the List<Files>)
let user choose the location once (in phone memory or m/m card)
and then simply copy all files in the same location one by one through the foreach loop (because you have the StorageFolder, you can use StorageFile's CopyAsync method)
I've done this in my WP store App (kind of File Explorer).
Hope this helps..!

How to encrypt folders and files for a wpf application

I'm working on a WPF project which is in charge to display a picture library.
The pictures are stored on folders.
I would like to know if there is a way to encrypt the folders and the pictures to protect the files (the user shouldn't see the files), but I want to keep the possibility to browse these folders by code to build my library.
The best way that I can think of is to store the files and folders in a Zip archive with a password. Zip files are supported natively by Windows. There are plenty of options for supporting zip files, including framework options and outboard libraries.
Note that this doesn't really protect the files from user tampering; it merely hides them from casual observers. Also, there may be a speed penalty; you should use the fastest possible options for compression.
you can use Zip archive and Another way:
you can add another project project(Library)into your main solution,add your image folders into your application and set their build action property to resource,with that,your images will store in an Dll and for can access them from Dll.i tried it before follow this link:
get-folder-address-in-dll

Identify an Office file write operation on Dokan file system

I'm using dokan as a file system and don't know how to identify office file write operation. Specially the lock and temp files.
I have to identify them because only the main file has to upload to an external database.
Theoretically I get office word to work but this is more a workaround. I hope there is a special attribute to identify there temp files.
Regard Chris
You can check the ProccessId to see if its Office's proccess. Check if the filename matches temp file. Some Office versions call CreateFile with FILE_FLAG_TEMPORARY and som set it later in SetAttributes. The best way is delay file upload till Cleanup and even then you can add an timer to uplosd it couple of seconds later. (Not sure but I think I remember that OpenOffice closes temp file and then opens it again to call MoveFile).
Hope it helps.

Best way to store a file temporarily untill the usage of file

As we all know that we can not get the full path of the file using File Upload control, we will follow the process for saving the file in to our application by creating a folder and by getting that folder path as follows
Server.MapPath
But i am having a scenario to select 1200 excel files, not at a time. I will select each and every excel file and read the requied content from that excel and saving the information to Database. While doing this i am saving the files to the Application Folder by creating a folder Excel. As i am having 1200 files all these files will be saved in to this folder after each and every run.
Is it the correct method to follow or not I don't know
I am looking for an alternative solution rather than saving the file to folder. I would like to save the full path of file temporarily until the process was executed.
So can any tell me the best way as per my requirement.
Grrbrr404 is correct. You can perfectly take the byte [] from the FileUpload.PostedFile and save it to the database directly without using the intermediate folder. You could store the file name with extension on a separate column so you know how to stream it later, in case you need to.
The debate of whether it's good or bad to store these things on the database itself or on the filesystem is very heated. I don't think either approach is best over the other; you'll have to look at your resources and your particular situation and make the appropriate decision. Search for "Store images on database or filesystem" in here or Google and you'll see what I mean.
See this one, for example.

Categories

Resources